I have a really strange problem that I have never seen before. I am using Django 1.10.
I have several dictionary files:
/locale/fr/LC_MESSAGES/django.po
/locale/de/LC_MESSAGES/django.po
/locale/zh/LC_MESSAGES/django.po
Application strings are written in English. Dictionary files are completed and compiled into files mo.
I keep each user's preference in the field language UserProfile. When updating my profile, I apply language translation to the session.
up.update(language=form.cleaned_data['language'])
translation.activate(up.language)
self.request.session[translation.LANGUAGE_SESSION_KEY] = up.language
return super(self, UpdateUserProfile).form_valid(form)
This is great for French and German. return superdisplays the form template in French / German, and then I can go to other pages and see the French / German text.
( "zh" ). return super ( ), , .
dev , - . VM. . ?
- :
settings.py
LANGUAGE_CODE = 'en-us'
LOCALE_PATHS = [
BASE_DIR + '/locale/',
]
USE_I18N = True
USE_L10N = True
, POST UpdateLanguage FormView request.session[translation.LANGUAGE_SESSION_KEY] zh, . GET ( request.session[translation.LANGUAGE_SESSION_KEY] , zh, ).
URL-.