onkar
onkar

Reputation: 4547

python django translation .po and .mo file not translating the files

I am trying to create a project using for 2 languages german and English

My Settings File

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

MIDDLEWARE = (
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

How I am running this tool

python manage.py makemessages -a 
This tool runs in debug mode
processing locale en
processing locale de
python manage.py compilemessages
This tool runs in debug mode
processing file django.po in app/locale/de/LC_MESSAGES
processing file django.po in app/locale/en/LC_MESSAGES

File Location app_ac/locale/de/LC_MESSAGES

-rw-rw-r--. 1 root root 421 May 11 11:44 django.mo
-rw-rw-r--. 1 root root 44K May 11 11:43 django.po

I am not getting the desired translations, I feel might be something is going wrong in .mo file as the size is just 421bytes as comparted to .po file which is 44Kb

EDIT 1

I have just figured out that in django.po file

The file looks like this

#: project/settings.py:184
msgid "German"
msgstr ""

#: project/settings.py:185
msgid "English"
msgstr ""

Instead of (What would ideally be, Sorry for my poor German)

#: .\project\settings.py:185 
msgid "German" 
msgstr "Deutsch" 

#: .\project\settings.py:186 
msgid "English" 
msgstr "Englisch" 

Upvotes: 2

Views: 3385

Answers (1)

onkar
onkar

Reputation: 4547

I just figured out that the translation messages were missing in the po file, replaced them with appropriate messages then ran the python manage.py compilemessages command, Now the translation works like a charm !!

Upvotes: 4

Related Questions