Django Translation Using .po File

When comes to using multiple languages in one single site, Django is very handy. You can use .po file to do your translation for you.

Process is very simple: First create .po file. To make .po file I would suggest to use poedit or Rosetta. Here is another option that is using django's very own Localisation. Second create a folder name locale within tour django project and add the language named (for example: ru_RU for Russian language) within locale. Within ru_RU folder, create another folder named 'LC_MESSAGES'. There save the .po file you have created. Save the .po file in name django.po. File Map:

Project
  |
  locale
    |
    ru_RU
      |
      LC_MESSAGES
        |
        django.po

Now run this command: django-admin.py compilemessages to generate .mo file(django.mo). Third comes to final touch. in Language settings in your settings.py add ru_RU like this:

LANGUAGES = (
    ('en-us', 'English'),
    ('ru_RU', 'Russian'),
)


LANGUAGE_CODE = 'en-us' 'ru_RU' 

Add locale path :

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

and finally add a middleware in in MIDDLEWARE_CLASSES.

'django.middleware.locale.LocaleMiddleware'

That should the trick.

comments powered by Disqus