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:

├── locale
│   ├── ru_RU
│   │   └── LC_MESSAGES
│   │        └── django.po
│   └── en_GB
│       └── LC_MESSAGES
│           └── django.po

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

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

LANGUAGE_CODE = 'en-us' 'ru_RU'

Add locale path :

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

and finally add a middleware in in MIDDLEWARE_CLASSES or MIDDLEWARES.


That should the trick.

Last updated: Jul 13, 2024

← Previous
Checking Database Permissions (MSSQL) with SQL Alchemy and Pydantic

Making sure the MSSQL connection is working fine. (Bonus) Checking it before the deployment using FAST API

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