Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.