From f13dbb2dbb27f8c83bbda3fc5b5ef4506b2d7b95 Mon Sep 17 00:00:00 2001 From: Wille Marcel Date: Wed, 16 Jun 2021 07:24:15 -0300 Subject: [PATCH] Update translation documentation and remove unneeded command (#4745) * Update translation documentation and remove unneeded command * Improve text * Fix command * Adding language instructions --- docs/contributing-translation.md | 21 ++++++++++------- manage.py | 39 -------------------------------- 2 files changed, 13 insertions(+), 47 deletions(-) diff --git a/docs/contributing-translation.md b/docs/contributing-translation.md index 56ca06427f..c0fbce05dc 100644 --- a/docs/contributing-translation.md +++ b/docs/contributing-translation.md @@ -21,22 +21,27 @@ In the project's top level directory, initialize Transifex service: `tx init`. T The .tx folder contains the Transifex config file. This is where you can find the mappings to local translation files. -### Extract strings for translation +### Update translation strings -* ```python manage.py build_locales``` - Collects translatable strings and moves them into `frontend/src/locales/en.json`, and updates the new keys on the other languages supported by TM. -* Push to the `develop` branch and it will be automatically picked up by Transifex (twice a day). +* ```yarn build-locales``` - Execute that command in the `frontend` folder to get the new translatable strings from all the `messages.js` files in the frontend code. The changes in the strings will be pushed to `frontend/src/locales/en.json` file. The ideal is to execute that command before every pull request that change something in the translatable strings. +* After the pull request is merged to the `develop` branch, the command `tx push -s` needs to be executed in order to push the changes to Transifex. The translators receive a notification every time we push changes to Transifex. ### Update with latest translations -* Before a release new translations need to be pulled in: ```tx pull -af --mode translator``` - Gets all translations from Transifex and puts them into `frontend/locale`. +* Before a release, new translations need to be pulled in: ```tx pull -af --mode translator``` - Gets all translations from Transifex and puts them into `frontend/src/locales/`. +* The [Transifex dashboard](https://www.transifex.com/hotosm/tasking-manager/dashboard/) can be used to check the status of the translations. If a language is not enabled in the `.tx/config` file, the translation updates will be downloaded to the `.tx/tasking-manager.version-4/` folder. ### Adding a new language -In this example we are adding support for German. +The steps required to add a new language support to Tasking Manager are the following: -* Add a new .json file with the appropriate language code as the name of the file, so in this case `de.json`. -* Configure local mapping by using Transifex's set command: ```tx set -r tasking-manager.master -l de frontend/src/locales/de.json``` -* Add the new language and language code to the config file so it shows up in dropdowns etc. in backend/config.py +* Add the language support using the [Transifex dashboard](https://www.transifex.com/hotosm/tasking-manager/dashboard/); +* Edit `.tx/config` and add a line like: `trans.ml = frontend/src/locales/ml.json` +* Add the new language and language code to: + * The `SUPPORTED_LANGUAGES` dictionary in the config file `backend/config.py`; + * The `supportedLocales` array on `frontend/src/utils/internationalization.js`; + * The polyfills in `frontend/src/utils/polyfill.js`; + * If the new language is not yet supported by [iso-countries-languages](https://github.com/hotosm/iso-countries-languages), we need to update it and publish a new version. ### Pushing translations diff --git a/manage.py b/manage.py index f27eefab01..8f7fcbc43c 100644 --- a/manage.py +++ b/manage.py @@ -1,8 +1,6 @@ import os -import subprocess import warnings import base64 -import json import csv import datetime @@ -109,43 +107,6 @@ def refresh_project_stats(): print("Project stats updated") -@manager.command -def build_locales(): - print("building locale strings...") - print("running: npm build-locales") - output = subprocess.Popen( - "npm run build-locales", shell=True, cwd="./frontend", stdout=subprocess.PIPE - ).stdout.read() - print(output) - lang_codes = [ - a.strip() for a in application.config["SUPPORTED_LANGUAGES"]["codes"].split(",") - ] - locale_path = "frontend/src/locales/" - en_locale_path = f"{locale_path}en.json" - - en_locale = json.loads(open(en_locale_path, "r").read()) - - for lang_code in lang_codes: - - # skip english - if lang_codes == "en": - continue - - current_locale_file = f"{locale_path}{lang_code}.json" - - if os.path.exists(current_locale_file): - current_locale = json.loads(open(current_locale_file, "r").read()) - else: - current_locale = {} - - for key in en_locale: - current_locale[key] = current_locale.get(key, "") - - with open(current_locale_file, "w") as locale_file: - locale_file.write(json.dumps(current_locale, indent=3)) - print(f"updated locale {lang_code} on file {current_locale_file}") - - @manager.command def update_project_categories(filename): with open(filename, "r", encoding="ISO-8859-1", newline="") as csvfile: