M
M
maximkalga2015-09-15 14:14:44
Django
maximkalga, 2015-09-15 14:14:44

How to force the desired language in Django 1.8?

Translated the site into Dutch.
I set everything in the settings:

USE_I18N = True

LANGUAGE_CODE = 'nl'

LANGUAGES = (
    ('en', 'English'),
    ('nl', 'Holland'),
)

LOCALE_PATHS = (
    location('locale'),
)

Urls without translations, there is such logic.
If you comment out 'django.middleware.locale.LocaleMiddleware' in settings, then the language is Dutch, but sometimes, for example, when you go to the search results page, it becomes English again by itself. If the search without parameters, then everything is OK - Dutch. If you uncomment LocaleMiddleware, then always English.
Added another middleware, also did not help:
class ForceDefaultLanguageMiddleware(object):
    def process_request(self, request):
        if request.META.has_key('HTTP_ACCEPT_LANGUAGE'):
            del request.META['HTTP_ACCEPT_LANGUAGE']

I saw this description:
Django determines the user's language like this (if not found, then goes further):
Looks for the django_language key in the user's session Looks in
cookies Looks
for Accept-Language in HTTP headers, and tries to find languages ​​allowed in the application (in the LANGUAGES variable)
Uses the value of the LANGUAGE_CODE variable

How to ironically set the Dutch language forever? English is not used, but serves only for labels when copying a site and translating it into other languages ​​(individual sites).

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
maximkalga, 2015-09-16
@maximkalga

Everything turned out to be much easier. It was necessary to just leave one language:
LANGUAGES = (
('nl', 'Holland'),
)

Z
zigen, 2015-09-15
@zigen

Try adding

USE_L10N=True
in settings

M
Max, 2015-09-16
@zenwalker

Can be called in middleware:

from django.utils import translation
translation.activate('hl')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question