zashi-android icon indicating copy to clipboard operation
zashi-android copied to clipboard

[PoC] [DNM] Add Jinja2 templating to all strings.xml files for multi-language support

Open y4ssi opened this issue 7 months ago • 0 comments

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:

  1. 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.
  2. Translation Dictionary:

    • Use the provided translation dictionary (see below) for translations.
    • Save this dictionary in a JSON file named translation_zashi.json inside the locales-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)
  }
}
  1. Script to process strings.xml files:

    • Create a Python script named translation.py inside the locales-tools directory.
    • The script should use Jinja2 to process all strings.xml.jinja2 files in the project, applying translations from the dictionary and creating values-{language} folders for files that differ from English.
  2. Modify strings.xml files:

    • Update all strings.xml files to use Jinja2 template variables.
    • Example of an updated strings.xml.jinja2 file:
<resources>
    <string name="account">{{ translation_dict['Account'] }}</string>
    <string name="send">{{ translation_dict['Send'] }}</string>
    <!-- Add similar entries for other keys -->
</resources>
  1. Run the script:
    • Execute the script to process all strings.xml.jinja2 files and apply the translations.
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 the strings.xml files.
  • The locales-tools directory is created and contains all necessary scripts and tools.

y4ssi avatar Jul 30 '24 16:07 y4ssi