Skip to content
Advertisement

Is there a way I can automate the creation of .json files used for language translations?

I have files such as this that have translation keys and values:

JavaScript

When I add a new translation key to the JSON file containing the English translations for example, I must remember to add that key and the associated translation to all the other JSON files. All the JSON files are also edited separately. The process is laborious and error prone.

Has anyone found a way to reduce the errors and to automate the process.

Ideally I would like to be able to run a script from Windows PowerShell that would change the files to this if an additional key was added to locale-en.json :

JavaScript

Advertisement

Answer

You could write something like this in powershell:

JavaScript

It created a dictionary from your English json file. Then it looks up all other locale files and checks them for keys which are present in the English file but missing from them. Then it adds the missing keys and values and saves the locale files in Unicode.

Let me show you how you can do the same with old school Windows Scripting since you seem to prefer JavaScript:

JavaScript

You can run the javascript from command line like this:

JavaScript

I hope it helps.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement