1
  1. I included the following in the settings.py:

    LANGUAGES = (
        ('en', 'English'),
        ('ru', 'Russian'),
    )
    
    LANGUAGE_CODE = 'en-us'
    
    USE_I18N = True
    
  2. marked the strings to be translated

    _('Enterprise')     # _ is lazy translate
    
  3. included this in my URLCOnf:

    url(r'^i18n/', include('django.conf.urls.i18n'))
    
  4. created the locale folder and did this:

    python manage.py makemessages -l ru
    
  5. translated the strings and did this:

    python manage.py compilemessages
    
  6. wrote this form:

    <form action="/i18n/setlang/" method="post">
            {% csrf_token %}
            <input name="next" type="hidden" value="/" />
            <select name="language">
               {% for lang in LANGUAGES %}
               <option value="{{ lang.0 }}">{{ lang.1 }}</option>
               {% endfor %}
            </select>
            <input type="submit" value="Translate" />
     </form>
    

I think I did all the steps to make it work but seems like I doing something wrong or missing something.

When use the form and try to translate and print request.LANGUAGE_CODE, it is showing me expected value. But the strings remain in the same language as they were

What is wrong here?

  • This smells like an incorrect path issue... Check my answer to this question http://stackoverflow.com/questions/20518783/django-1-5-5-displays-original-en-strings-always-does-not-translate – Serafeim Feb 21 '15 at 11:26
  • @Serafeim, thanks for pointing me in the right direction. –  Feb 21 '15 at 11:37
  • No problem! you can also +1 my answer :) – Serafeim Feb 21 '15 at 19:06
  • @Serafeim I definitely will when I have enough reputation :) –  Feb 25 '15 at 10:26

2 Answers2

6

Probably you forgot to add the locale middleware into your settings file it should look like this

'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware', 
'django.middleware.common.CommonMiddleware',

You should take into consideration that the locale middleware should preced the commonmiddleware And comes after the Sessionmiddleware As it takes it argument from the session middleware

Igor Jerosimić
  • 13,621
  • 6
  • 44
  • 53
Mina Samy
  • 96
  • 1
  • 5
1

You should define your LOCALE_PATHS in settings.py file like this

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

django doesn't by default look for locale dir in root of project.

GwynBleidD
  • 20,081
  • 5
  • 46
  • 77