This script processes our current .h translation files into JSON. It reads the master translation (en-us.h), populates keys with all available text values from other translation (zh-cn.h), and saves to a simple JSON file (zh-cn.json). Some of our translations (chinese) are old and have missing values, this fills them with default English text and saves everything as JSON for the next step.
json2h.py
>python json2h.py
This script:
Reads the base translation (en-us.h)
Creates a new base.h with all the keys from en-us.h (base.ht is the template file)
Processes all the other .json files in the folder into .h files, filling in with default values from en-us.h where things are missing. (translation.ht is the template file).
Proposed workflow:
Developers add a single new tag and text to en-us.h
h2json.py runs at compile time (or with a folder change watch), reading en-us.h and creating a matching base.h file. Then translation .json is parsed to .h files with defaults filled for missing values.
I think this would be a lot more usable than the current situation.
The other part of this will be a web browser app that (hopefully) reads translation .json files from our github repo for easy online translation additions and updates.
I pushed the scripts to a new branch, but it’s really small so I attached it here too. If you’re able to try out a python script please share your thoughts.
One last thing for the night. Here’s a modern javascript webpage (probably needs to be run from a server like laragon) that fetches the .json from github and shows it in rows for editing.
Click download JSON to get a .json file straight from the browser. (sample data only at the moment).
TODO
Create new translation option (what to name download?)
Reload JSON option (resume work? save in browser indexDB?)
Wow, I’m really glad to see .json is an acceptable format for localization. This is such great stuff.
Is that a site/app that I can use to host our own json files for localization? Are there any developer tools to integrate it?
It used to be such a pain to add new text to translation - make a key, then update every translation with that key plus default value. What happens in practice is that everything but english is commented out and falls behind.
I did some updates with our new python script. Only add an entry in english.h, the tags file and the other translations are automatically generated in a fraction of a second. And, it generates .h files so there’s no need to setup an extensive toolchain just to get our source compiling.
There is an issue with the prior design of the JSON localization.
Steps to repro:
Find a string in one of the translations that isn’t actually translated yet (identical to EN-US string)
Edit the EN-US string for that existing string ID
Expected results:
The translations which have not actually translated the string get the updated EN-US string displayed.
Actual results:
Once an EN-US string is copied to the translation JSON, it is never updated, even if the EN-US string is updated.
Fix
Any non-translated string should be removed from the translation’s JSON.
Any editing webpage should load the EN-US as well as the translation JSON. If the string exists only in EN-US, it’s not been translated. The buspirate firmware was already updated to automatically load the EN-US string in such a case.
This is a good point. So one update to the python script to skip instead of fill, and an update to the little web app to use en-us as the base over the translation file.
Not sure how to best tackle this, but there’s a third issue that will eventually arise related to format arguments… See GitHub issue 185 for details on issue and recommended way to improve.