zashi-android
zashi-android copied to clipboard
[PoC] [DNM] Add Jinja2 templating to all strings.xml files for multi-language support
THIS IS A PoC
Summary:
We need to enhance our localization process by incorporating Jinja2 templating into all strings.xml
files. This will allow us to use a dictionary for translations and make it easier to manage multiple languages in the app. In the future, this dictionary will be housed in a separate repository, and we aim to implement a similar approach for iOS. This commit serves as an example of work that is still in progress.
Objective:
- Integrate Jinja2 templating in all
strings.xml
files. - Use the provided translation dictionary to populate the
strings.xml
files.
Details:
-
Create a new directory for localization tools:
- Create a new directory named
locales-tools
at the root of the project. - This directory will contain scripts and tools related to the localization process.
- Create a new directory named
-
Translation Dictionary:
- Use the provided translation dictionary (see below) for translations.
- Save this dictionary in a JSON file named
translation_zashi.json
inside thelocales-tools
directory.
{
"translation_dict": {
"Account": { "en": "Account", "es": "Cuenta" },
"Send": { "en": "Send", "es": "Enviar" },
"Receive": { "en": "Receive", "es": "Recibir" },
"Balances": { "en": "Balances", "es": "Saldos" }
// ... (all other dictionary entries)
}
}
-
Script to process
strings.xml
files:- Create a Python script named
translation.py
inside thelocales-tools
directory. - The script should use Jinja2 to process all
strings.xml.jinja2
files in the project, applying translations from the dictionary and creatingvalues-{language}
folders for files that differ from English.
- Create a Python script named
-
Modify
strings.xml
files:- Update all
strings.xml
files to use Jinja2 template variables. - Example of an updated
strings.xml.jinja2
file:
- Update all
<resources>
<string name="account">{{ translation_dict['Account'] }}</string>
<string name="send">{{ translation_dict['Send'] }}</string>
<!-- Add similar entries for other keys -->
</resources>
-
Run the script:
- Execute the script to process all
strings.xml.jinja2
files and apply the translations.
- Execute the script to process all
python locales-tools/translation.py
Future Work:
- The translation dictionary will be moved to a separate repository.
- Implement a similar localization approach for the iOS version of the app.
Acceptance Criteria:
- All
strings.xml
files are updated to use Jinja2 templating. - The
translation.py
script correctly applies translations from the dictionary to thestrings.xml
files. - The
locales-tools
directory is created and contains all necessary scripts and tools.