Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterjaap/98b69daf2485de8ff28b7b897200cb17 to your computer and use it in GitHub Desktop.
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
<?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