Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update translation documentation and remove unneeded command #4745

Merged
merged 4 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions docs/contributing-translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 0 additions & 39 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os
import subprocess
import warnings
import base64
import json
import csv
import datetime

Expand Down Expand Up @@ -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:
Expand Down