简体   繁体   中英

Django translation not working on production

I've made translation of the site for different cities and it works fine on dev machine. But when published on production server it didn't show any translation.

But it shows available languages and current language correctly.

Here's my settings.py:

USE_I18N = True
USE_L10N = True
LANGUAGES = [
    ('ru-spb', _('SaintP')),
    ('ru-msk', _('Moscow')),
]

LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'nordicsite/locale'),
)

Here's template for language check:

 {% load i18n %}
 {% get_current_language as LANGUAGE_CODE %}
 {% get_available_languages as LANGUAGES %} 
 {% get_language_info_list for LANGUAGES as languages %}

 {{server}}<br/>
 {% trans 'Test 2' %}<br/>
 {{LANGUAGE_CODE}}<br/>
 {% for language in languages %}
     {{ language.name_local }} ({{ language.code }})<br/>
 {% endfor %}
 <br/>
 {% for path in paths %}
     {{path}}<br/>
 {% endfor %}

Output for dev:

Тест 1 Питер
Тест 2 Питер
ru-spb
Русский (ru) 
Русский (ru) 

/*****/nordicsite/locale

Output for production:

Test 1
Test 2
ru-spb
Русский (ru) 
Русский (ru) 

/*****/nordicsite/locale

What can be wrong?

Finally i figured out what was wrong. My dev machine - Mac and production - Ubuntu. And it didn't work width fake language codes like ru-spb and ru-msk. I changed it to ru-ru and ru-ua and started working correctly.

One more thing. Ubuntu needs locale folder to be ru_RU (not ru_ru).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM