Search code examples
djangogettextdjango-2.0

django2.0 international not work in my server environment


I trapped in a problem for a while. I do as the documentation and i get the result as i want in the local environment. Not only using python3 manage runserver but also uwsgi --http :8000 xxx.uwsgi. But after i upload my files into my server, i can not get the same result as the local environment.

Here is the configuration:

LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
# print(LOCALE_PATHS)

LANGUAGE_CODE = 'en-us'

LANGUAGES = [
    ('en-us', t_l('English')),
    ('zh-hans', t_l('Chinese'))
]

USE_TZ = True
TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'util.middleware.MultipleDomainMiddleware',
    'util.middleware.VisitHistoryMiddleware',
    'django.middleware.gzip.GZipMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    # 'debug_toolbar.middleware.DebugToolbarMiddleware',
]

And the url of .mo, .po file is '/project/locale/zh_hans/LC_MESSAGES/xxx.po', '/project/locale/zh_hans/LC_MESSAGES/xxx.mo'

Of course, i add {% load i18n %} to the top of my web page. The function works fine in my local environment, but not working in my server environment.

I use nginx + uwsgi + django to deploy my server. And i can make sure that the server get the actually request.LANGUAGE_CODE. I tried to use python3 manage runserver and uwsgi --http to run my code on the server to see if the translation works. The answer is no!

The system version of my server is Ubantu 16.04, the version of gettext in my server is 0.19.7-2ubuntu3. I use apt-get to install gettext.

And who knows how to solve my question?


Solution

  • I overcome this problem by change the url /project/locale/zh_hans/LC_MESSAGES/xxx.mo' to /project/locale/zh/LC_MESSAGES/xxx.mo'.