View translations in django templates (e.g. making it work)

I am trying to figure out the django translation system, so I wrote a small test application. I created translation files and compiled them (* .po and * .mo), and now I'm trying to display the template in another language. I am changing LANGUAGE_CODE in my settings.py to a different language code, but the template is still displayed in English. There are no errors, I just don’t see another language that I am trying to execute, although I translated, compiled and all that. I have db configured to support all the necessary. I also used get_current_language in the template:

{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_current_language_bidi as LANGUAGE_BIDI %}
the current language is {{ LANGUAGE_CODE }}

but I get an empty place where the code should appear. What am I missing? thanks.

+3
source share
2 answers

This is probably one of two problems:

  • Make sure you have django.core.context_processors.i18ninsettings.TEMPLATE_CONTEXT_PROCESSORS

  • Make sure you pass RequestContext(request)in quality context_instanceif you create your template usingrender_to_response

+3
source

Perhaps you left USE_I18N = Falsein your settings. view documents

0
source

Source: https://habr.com/ru/post/1724385/


All Articles