Skip to content

Scripts

Diego edited this page Feb 10, 2020 · 6 revisions

This section intends to explain all scripts in the folder /dev_scripts

Translation

The main intention of this script is to simplify the way that strings in localization files are manipulated by either translators or developers.

All localization files in the folder ./src/localization like authStrings.json, buttonStrings, demoUserModalStrings, etc. have a similar structure, represented by this example:

  "gb": {
    "logging_in": "Logging in...",
    "login": "Login",
    "password": "Password",
    "repeat_password": "Please re-enter password",
  },
  "fr": {
    "logging_in": "Connexion en cours",
    "login": "Se connecter",
    "password": "Mot de passe",
  },
  "gil": {
    "logging_in": "Taninga bwa e na uki",
    "login": "Kaukia",
    "password": "Am ka-ukuki",
    "user_name": "Aram ae kinaaki ikai"
  },
  "tl": {
    "logging_in": "Rejistu hela...",
    "login": "Rejistu",
    "password": "Liafuan-pase",
    "user_name": "Naran"
  },
  "la": {
    "logging_in": "ກຳ​ລັງ​ເຂົ້າ​ລະ​ບົບ",
    "login": "ເຂົ້າ​ລະ​ບົບ",
    "password": "ລະຫັດຜ່ານ",
    "user_name": "ຊື່​ຜູ້​ນຳ​ໃຊ້"
  }
}

In that case, authStrings.json has different values related with its language. English is the default language for those cases in which a language does not have a translation.

In order to create a CSV file that Includes all the strings related with one selected language, French (fr) for example, this application is getting all the corresponding texts from the localization files and places them in a unique CSV file named, for this example, fr.csv. As a general rule, [language].csv

Available languages to translate from English (at the moment), are:

  • French (fr)
  • Kiribati (gil)
  • Tetum (tl)
  • Lao (la)

Usage

Exporting strings for existing languages

yarn translation export [selectedLanguage]

# selectedLanguage can be any of this options: fr, gil, tl, la

After that, a file with extension .csv will be added to ./src/localization/translations. If the selectedLanguage is French, the new file will be fr.csv.

That file can be edited using Google Sheets and when ready, save as .tsv (tab separated values).

Important: Even if the file is not modified, once generated needs to be save as tsv before being imported as json. (See complete example at the end)

Importing strings

The inverse process is importing the changes to its corresponding .json file using the following command:

yarn translation import [selectedLanguage]

# selectedLanguage is the language to be imported: fr, gil, tl, la
# It should match with the language of the CSV file to be imported

After that, all localization files will be updated based on the changes that have been made in the CSV file.

Process for new languages (Work in progress to add this feature)

In case a new language is added, the idea is to generate a file with, for example, French strings, and then remove the last column (the one that has the French words). The the process of exporting will be similar as any other existing language.

For example, for Portuguese the steps would be:

  1. yarn translation export fr
  2. Remove the last column
  3. Add the Portuguese strings
  4. yarn translation import pr

Then the process continues as any other language.

Complete example for export and import in French.

  • Type: yarn translation export fr in the command line. A file named fr.csv should be generated in src/localization/translations
  • Open the generated CSV file in Google sheets
  • Columns from left to right should show the corresponding files name, keys in English, values in English and values in selectedLanguage (in french for this example).
  • Add a translation for a string that it doesn't has a value in French. Like in this example, add THIS IS AN EXAMPLE as a value for repeat_password in french.
Screen Shot 2019-12-17 at 12 38 43 PM
  • Download the file as tsv (tab separated values). That new file should be in your default Downloads folder, and rename it as fr.tsv (That's really important, otherwise it won't work)
  • Place fr.tsv in src/localization/translations
  • Check that the file looks like a TSV file:

Example:

Screen Shot 2019-12-20 at 10 20 31 AM

  • Then run: yarn translation import fr in the command line.
  • Find the successful message in the console.
  • In src/localization/authStrings.json check that the added value must exist and it should be the same as the one previously created.

Example:

Screen Shot 2019-12-20 at 10 25 03 AM