Created
June 18, 2019 12:51
-
-
Save peterjaap/98b69daf2485de8ff28b7b897200cb17 to your computer and use it in GitHub Desktop.
Convert Deity translation JSON file to OneSky CSV format. Usage; php convertTranslationJson.php client/node_modules/@deity/falcon-i18n/i18n/en/translations.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$input = json_decode(file_get_contents($argv[1])); | |
$output = []; | |
foreach ($input as $aKey => $aValue) { | |
if (is_object($aValue) || is_array($aValue)) { | |
foreach ($aValue as $bKey => $bValue) { | |
if (is_object($bValue) || is_array($bValue)) { | |
foreach($bValue as $cKey => $cValue) { | |
if (is_object($cValue) || is_array($cValue)) { | |
throw new Exception('not implemented!'); | |
} else { | |
$output[$aKey . '.' . $bKey . '.' . $cKey] = $cValue; | |
} | |
} | |
} else { | |
$output[$aKey . '.' . $bKey] = $bValue; | |
} | |
} | |
} else { | |
$output[$aKey] = $aValue; | |
} | |
} | |
$csv = 'id,string'; | |
foreach ($output as $key => $value) { | |
$csv .= PHP_EOL . $key . ',' . $value; | |
} | |
echo $csv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment