About Temporary Language Switching
You can override a language temporarily using the override()
function:
from django.utils.translation import override, gettext
from django.conf import settings
def greeting_translated():
greeting = {}
for lang_code, lang_name in settings.LANGUAGES:
with override(language=lang_code):
greeting[lang_code] = gettext("Hello, World!")
return greeting
Tips and Tricks Translations Django 4.2 Django 3.2 Django 2.2
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django App for You
Django GDPR Cookie Consent app
For Django websites that use cookies.
Django App for You