13

I have a problem with django translations.

Problem 1 - I updated string in django.po file, but the change does not appear on the webpage.

Problem 2 - I have created my own locale file with django-admin.py makemessages -l et, added the translation string into file, but they too do not appear on the page.

I do not think this is setting problem, because the translations from django.po file do appear on the website, its just the changes and the translations from my own generated file that do not appear.

Edit: My settings.py contains this:

gettext = lambda s: s
LANGUAGE_CODE = 'et'

LANGUAGES = (
             ('et', gettext('Estonian')),
             )

my own locale files are in

/path/to/project/locale/et/LC_MESSAGES/

and the files are

django.mo and django.po

the file I refer to in problem 1 is django own et transaltion, which I changed.

Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90
Odif Yltsaeb
  • 5,575
  • 12
  • 49
  • 80
  • Are you ready the doc about [i18n](http://docs.djangoproject.com/en/1.1/topics/i18n/internationalization/#topics-i18n-internationalization)? I'm guessing, but do you enable i18n tag in templates? Are you sure your .po file is in the right path? Can you write more info? – diegueus9 Apr 14 '10 at 18:13
  • Well yes. i18n is enabled in templates with {% load i18n %}. Since the django.po file is in correct path (problem 1) i dont think its the problem of either enabling or loading i18n. Since like i said - existing translations are beeing loaded into template. But how do i know if the problem 2 locale files are in correct place? They are in the place where they were generates by django-admin.py makemessages -l et – Odif Yltsaeb Apr 14 '10 at 18:31
  • read this: http://docs.djangoproject.com/en/1.1/topics/i18n/localization/#message-files the path will be: your_project/locale/et/LC_MESSAGES/django.po. – diegueus9 Apr 14 '10 at 18:41
  • Well, thats exactly where my self generated files are, so whats the problem? – Odif Yltsaeb Apr 14 '10 at 18:46
  • again, i'm guessing, do you compile your .po file? are you sure yo don have problems with the .po file? – diegueus9 Apr 14 '10 at 18:48
  • Yes i compiled my own .po file. it created .mo file in my locale folder. So that should not be a problem too. how would i know if i had problems in my .po file? I did not do anything other than enter translation strings between empty "". – Odif Yltsaeb Apr 14 '10 at 18:57
  • It' s weird. Once i had a problem with the coding of file when i upload to the server. Can you give us more information, what version of python, django, apache? gettext? may show us your settings, a fragment of templates/views with i10n, what editor of .po are you using? – diegueus9 Apr 14 '10 at 19:05
  • Do you just check the html templates ? One idea would be to restart your webserver (or django process) but i guess that already happened. I would suggest you to go low level. Try on a django shell to translate a sample word that you are sure is within the .po file and compiled. That way you will be sure that gettext files and django translation system works (or not). one way to test the translation is the following from django.utils.translation.trans_real import translation t = translation("et") print t.gettext("sampleword") – vinilios Apr 30 '10 at 02:09

7 Answers7

27

Well, I got this same error a few moments ago. I solved it deleting the "#, fuzzy" tag over the translation strings in my django.po files. It seems that translated text is not served if it got this tag, so make sure to translate the text and then delete this line.

Here is an example of a translated text not server on a po file:

     #: course/models.py:13
     #, fuzzy
     msgid "code"
     msgstr "código"

So, just delete the flag and leave it like this:

     #: course/models.py:13
     msgid "code"
     msgstr "código"

I hope this work for you. Good luck!

Reference: http://share-experiences.com/blog/what-fuzzy-means-python-django-gettext/

PD: I know you got this issue a few month ago, but I leave this response due that you we never heard if you got this problem solved.

FernandoEscher
  • 2,940
  • 2
  • 28
  • 27
12

Had a same/similar issue with translations not showing up. Setting the LOCALE_PATHS fixed the issue:

# settings.py
USE_I18N = True
USE_L10N = True

LOCALE_PATHS = (
  '/path/to/djangoapp/locale',
)
jmu
  • 3,619
  • 1
  • 23
  • 12
  • Hmm yeah django has recieved like 4 major upgrades since i posted the question. Locale paths are indeed one of the fixes to translations problem and they were added in django 1.4 i think. – Odif Yltsaeb Jun 14 '13 at 07:40
  • 2
    Even better I would recommend `os.path.join(BASE_DIR, 'locale'),`. **Don't** use relative paths as although they work in dev, they might not work live depending on server etc. I learned this the hard way. – Wtower Dec 15 '15 at 10:16
7

Translation files (PO) are loaded in memory only one time, changes to the PO files are not picked up by Django. In order to load the new translation files you need to restart Django (eg. stop/start runserver, Apache or NGINX).

Tommaso Barbugli
  • 11,781
  • 2
  • 42
  • 41
  • That you have to restart the django server is also my experience, but it's weird that it isn't mentioned anywhere in the documentation. – qff Oct 24 '14 at 15:18
1

One additional reason for Django translations not working is to compile the .po file with a Python version different than the one being used to run your application. Make sure you use the same version.

regiov
  • 41
  • 2
0

Make sure to use ugettext_lazy and not ugettext

Frido Emans
  • 5,120
  • 2
  • 27
  • 42
0

If you are using gettext.translation to get the translations, i.e:

text_de = gettext.translation('django', locale_dir, ['de'], fallback=True).ugettext('Welcome to my site')

... and your translation works on the development server but not on production, note that locale_dir must point to your locale directory. It might be located elsewhere on one of the systems. Spent like 2 hrs finding it.

-2

Check for the USE_I18N setting. More info. Anyway, I think by default it's True...

Armando Pérez Marqués
  • 5,661
  • 4
  • 28
  • 45