Two python script to convert JSON translation files to excel and the other way around. It has been created to work with I18n.
The character used of object nesting in json is the dot .
The following json structure:
{
"app": {
"name": "App Name"
}
}Produces a key named app.name
Flat json files are also supported (note: use -fk argument for excelToJson):
{
"app.name": "App Name"
}Clone the project:
git clone https://github.com/tiknil/json-excel-translations.git
cd json-excel-translationsSetup the virtualenv with the setup script:
chmod +x setup.sh
./setup.shNow you can use the script:
./jsonToExcel.py -o output/file -i input/folder
./exceltoJson.py -i input/file -o output/folderYou can use the link script to setup the scripts in your /usr/local/bin folder, so they can be used from everywhere:
sudo ./link.sh
jsonToExcel -o output/file -i input/folder
exceltoJson -i input/file -o output/folderThe scripts assumes a folder of .json files named after their respective locale: it.json, en.json, ...
It creates an excel file where each column represents a locale and each row is a translation key.
The key are obtained from the primary language (default en, it can be configured using the -p argument)
Assume we have a folder, named translations, with 2 files: it.json and en.json, where the primary language is it.
Given the command:
jsonToExcel.py -o translations.xlsx -i translations -p it
It produces an excel file named translations.xlsx structured as:
| key | it | en |
|---|---|---|
| keyName | italiano | inglese |
-hInstructions on the script usage-o/--output-filewhere the excel file must be created (defaultoutput/translations.xlsx)-i/--input-dirwhere the translation files are located (defaulttranslations/)-k/--key-namename of the excel column containing the keys (defaultkey)-n/--namea name of the excel sheet (defaultTranslations)-p/--primarya translation file name without .json to be used as the primary language (defaulten)-l/--localesA comma-separated list of the locales to select (default all json files in the input directory)
Given an excel files structured as in the table below
| key | locale1 | locale2 |
|---|---|---|
| keyName | locale1 string | locale2 string |
| keyName2 | ... | ... |
It produces a json file for each locale containing the corresponding translations.
-hInstructions on the script usage-o/--output-diroutpit directory for the translation files (defaulttranslations/)-i/--input-filelocation of the excel input file (defaultoutput/translations.xlsx)-e/--emptyset this flag to also include keys without a translation (default is to NOT include keys without a translation, assuming there is a fallback mechanism in your app for such strings)-k/--key-namename of the excel column containing the keys (defaultkey)-is/--indent-sizesize of the Json indentation (default is4)-fk/--flat-keysset this flag to keep composite keys in output json files which will make them flat key-values objects (default is to split composite keys by .)