Skip to content

Commit

Permalink
docs: overhaul docs on translation
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasschaub committed Feb 29, 2024
1 parent 1e75b6c commit b8eddc4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
10 changes: 10 additions & 0 deletions docs/development-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ ruff
ruff format
```

### Exceptions

The use of custom exceptions is highly encouraged.

To translate error messages all custom exceptions should inherit from the `TranslatableError` class (see `exceptions.py`).
A `TranslatableError` should have as first argument a message wrapped in a `N_()` function (see `helper.py`), to mark it for translation, and optionally a dictionary with values for interpolation.

> Note: For more information on translation please see [/docs/translation.md]

### Tests

```bash
Expand Down
23 changes: 13 additions & 10 deletions docs/translation.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
# Translation

## Internationalization

The Sketch Map Tool uses [Babel](https://babel.pocoo.org/en/latest/) through [Flask Babel](https://github.com/python-babel/flask-babel) for internationalization.
It is configured ([babel.cfg](../babel.cfg)) to look for strings to be translated in all Jinja2 HTML templates.
Text to be translated in Python files need to be manually selected and wrapped in a `gettext` function call (E.g. Error messages in `routes.py`).
Please refer to to the official documentation of [Flask Babel](https://python-babel.github.io/flask-babel/index.html#translating-applications) regarding the process of translating the application.

Additionally a function called N_ was added to mark strings for translation, this is mainly used in the context of errors, since they should not be translated in the error log, but need to be translated later when send to the users. If you want to raise a new Exception in the Code, please look at the already implemented examples.
## Translation via Crowdin

The Sketch Map Tool uses the platform [Crowdin](https://crowdin.com/) for translation.

# Automatic Approach:
Text marked for translation is send from GitHub to Crowdin via GitHub Action ([github-to-crowdin.yml](../.github/workflows/github-to-crowdin.yml)). The action triggers on push to `main`.

The Sketch Map Tool uses crowdin to help as a platform for translations. To get the strings which need to be translated the github
action [github-to-crowdin.yml](../.github/workflows/github-to-crowdin.yml) is used. It is executed once anything is pushed into origin/main.
Translated text is send from Crowdin to GitHub via GitHub Action ([crowdin-to-github.yml](../.github/workflows/crowdin-to-github.yml)). The action triggers regularly and results in a PR when new translations are available.

To get the translated strings from crowdin to github the github action [crowdin-to-github.yml](../.github/workflows/crowdin-to-github.yml)
is used. It runs daily and opens a new pullrequest if new translation string where added.
## Manual Translation

> Note: Since Crowdin is used for translation following section is not longer relevant.
# Manual Approach:
Without the help of tools like crowdin, things would have to look like this:
The basic process for translation on a local machine would look something like this:

## Add a new translation
### Add a new translation

```bash
pybabel extract -F config/babel.cfg -o messages.pot .
pybabel init -i messages.pot -d sketch_map_tool/translations -l de
pybabel compile -d sketch_map_tool/translations
```

## Update an existing translation
### Update an existing translation

```bash
cd sketch_map_tool
pybabel extract -F config/babel.cfg -o messages.pot .
pybabel update -i messages.pot -d sketch_map_tool/translations
pybabel compile -d sketch_map_tool/translations
```

0 comments on commit b8eddc4

Please sign in to comment.