Ruddra.com

Django Translation Using .PO File

Django Translation Using .PO File

This post is deprecated. Please follow the official documentation.

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.

How to do that

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
│   └── en_GB
│       └── 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 or MIDDLEWARES.

'django.middleware.locale.LocaleMiddleware'

That should the trick.

Last updated: Feb 29, 2024


← Previous
Add Outlook Shared Mailbox Rules for Disabling Notifications

Get rid of the all distractions when you are focusing.

Next →
RichText Editor in Django Admin Site

I wanted to add a rich text editor within django administrator. It is not that hard to add a rich …

Share Your Thoughts
M↓ Markdown