Adding translations

There are translatable strings from Python in udata.

We use Crowdin for translations on the project. First, you have to create an account.

After that you’ll be able to reach the udata crowdin page and interact with translations.

Warning

We only translate strings from the main and maintenance branches of the repository. Do not push languages on any other branch because merging translations is incredibly painful.

Existing languages

The command inv i18n extracts all these strings locally. Pushing the changes on any branch will automatically update translatable strings on Crowdin.

Crowdin will submit pull requests on GitHub each time translations are updated.

When pulling new translations in .po files, you should recompile translations with inv i18nc to generate .mo files.

Proposing a new language

To propose a new language you need to submit a pull request:

  • create a branch for the new translations (ex: add-language-fr)
  • in this branch, add the language to the LANGUAGES setting in your configuration file
  • submit the pull request

Once it has been accepted, we will also create the new language translation in Crowdin.

Adding translations in a plugin

You can also add translations in your backend plugin. They should be located inside your module directory and follow this layout.

├── udata_plugin
│   ├── translations
│   │   ├── xx/LC_MESSAGES
│   │   │   └── udata-plugin.po
│   │   └── udata-plugin.pot

If the translations directory is present and contains some gettext-based translations(po/mo files), they will be automatically discovered and loaded if the plugin is enabled (see extending udata).

All commands below should be run from your plugin project root (where pyproject.toml is located). Replace udata_plugin with your actual package name.

You can extract translations from your own templates using:

uv run pybabel extract -F babel.cfg -o udata_plugin/translations/udata-plugin.pot .

Then you can either add a new supported locale:

uv run pybabel init -l xx -i udata_plugin/translations/udata-plugin.pot -d udata_plugin/translations  # where xx is the locale you want to add. ex: fr

or update the existing ones:

uv run pybabel update -i udata_plugin/translations/udata-plugin.pot -d udata_plugin/translations

You can then translate the po file using the editor of your choice. You could take a look at Poedit or set up a Crowdin project if you want.

When translation is done, you can compile translations catalogs using:

uv run pybabel compile -d udata_plugin/translations

Warning

Don’t forget to compile and include translations in your plugin distribution when you publish it.