Django / Locale

Step 22 of 23

Enable locale handling

Altified uses Django's active language to decide when configured fields should return translated values.

Altified reads the current request language from django.utils.translation.get_language(). Your project's default language and target languages stay in the Altified dashboard, where the API key points to them.

settings.py
MIDDLEWARE = [
    ...,
    "django.middleware.locale.LocaleMiddleware",
    ...
]
  • Place LocaleMiddleware after SessionMiddleware and before CommonMiddleware when those middleware are used.
  • Use your existing Django locale handling to set the active request language.
  • Do not duplicate the Altified project default or target languages in Django settings.

If you need to request a specific language outside Django's active locale, pass it directly to the helper.

Python
from django_altified import translate_field

name_fr = translate_field(product, "name", language="fr")

Why this matters

The SDK sends the active locale to Altified. Altified validates it against the project connected to the API key and returns source text when the locale is the project default language.