Backend internationalization (i18n)
Backend internationalization covers a few translated database fields. All interface text is translated in the frontend: to fix or add a translation of anything shown in the UI, see the HomePort i18n guide.
Waldur's own backend messages (API errors, notifications) are not translated and are returned in English.
Messages that come from Django and Django REST framework themselves, such as This field is required., use
the translations bundled with those libraries and follow the request language.
Translated fields
These fields are stored once per language with django-modeltranslation:
| Model | Fields | Registered in |
|---|---|---|
Role |
description |
waldur_core/permissions/translation.py |
Category |
title, description |
waldur_mastermind/marketplace/translation.py |
CategoryGroup |
title, description |
waldur_mastermind/marketplace/translation.py |
The translation.py files are the source of truth if this table falls behind.
Each translated field gets one database column per language in LANGUAGES: description_en,
description_et and so on. Reading description returns the column for the language of the current request,
which LocaleMiddleware takes from the Accept-Language header. An empty column falls back to English.
Translations are entered by staff:
- Role descriptions — in the role description dialog of the roles administration, or through the
update_descriptionsaction of the roles API, which accepts onedescription_<lang>field per language. - Categories and category groups — in the Django admin, which shows one input per language.
Making another field translatable
-
Register the field in the app's
translation.py:1 2
class CategoryTranslationOptions(TranslationOptions): fields = ("title", "description") -
Run
makemigrationsfor the app. The migration adds one column per language. - To accept the per-language values through the API, use
TranslatedModelSerializerMixinfromwaldur_core.core.serializers. It adds a<field>_<lang>serializer field for each language.
Adding a language
- Add the language to
LANGUAGESinwaldur_core/server/base_settings.py. - Add its code to
LANGUAGE_CHOICESinwaldur_core/server/constance_settings.py, the default list of languages users can choose from. - Run
makemigrationsforpermissionsandmarketplace. The migrations add the new language's column to every translated field. - In HomePort, add
locales/<code>.json, and map the language code to the country whose flag the language selector shows inLanguageCountry(src/navigation/header/LanguageSelectorDropdown.tsx).
Do not use modeltranslation's sync_translation_fields command: it adds the columns directly to the database,
outside the migration history.