6

I've encountered a strange problem when translating strings (in the admin) using django's gettext: Locally running the dev server all translations are displayed correctly in the admin, but when the project is deployed on the production server some strings are not translated at all. I cannot determine any system behind which strings are affected and which not!

To give you an impression, eg. a model is defined like:

class Company(models.Model):

    ....

    class Meta:
        verbose_name = _('Company Profile')
        verbose_name_plural = _('Company Profiles')

Using dev server the model's name shows up correctly in different languages in the admin, on the production server not! This affects some models, others not... This is driving me really nuts, since I hardly have a idea on how to debug this...

tshepang
  • 12,111
  • 21
  • 91
  • 136
Bernhard Vallant
  • 49,468
  • 20
  • 120
  • 148

3 Answers3

7

A few possibilities:

  • production server doesn't see the compiled messages
  • the untranslated messages are marked as fuzzy
  • _() resolves to ugettext instead of ugettext_lazy
Tomasz Zieliński
  • 16,136
  • 7
  • 59
  • 83
  • They aren't marked as fuzzy, but can you maybe name some reasons why the server wouldn't see the compiled messages (they are in the app dirs). Haven't also read yet what the problem of using `ugettext` instead of `ugettext_lazy` is? – Bernhard Vallant Nov 05 '10 at 01:21
  • 1
    Ok. solved it now. I was inheriting from a model that used `ugettext`, while the child was using `ugettext_lazy`, so i got this strange mixture! Thanks! – Bernhard Vallant Nov 05 '10 at 02:19
  • What I meant was that maybe e.g. compiled messages were not commited to the server. Nothing magical, just that such trivial things sometimes happen. – Tomasz Zieliński Nov 05 '10 at 12:03
  • @ThomaszZielinski Thanks ! In my case, I had used a generic python `.gitignore` file which ignores `*.mo` files ! Such a stupid problem :P – achedeuzot Nov 20 '14 at 18:23
  • Nice answer to all kinds of possibility. This answer from 5 years ago can still save my ass. – Joey Sep 13 '15 at 06:00
3

I had a similar problem and apart from what Tomasz Zielinski pointed out I had to make the following changes:

in settings.py

LOCALE_PATHS = (
    "/path/to/your/project/locale",
)

Remember the trailing slash and make sure that the directory structure looks something like:

project
   your_app
   your_other_app
   locale
      en_US
          LC_MESSAGES
      sv_SE
          LC_MESSAGES
Joelbitar
  • 3,520
  • 4
  • 28
  • 29
3

If you are developing on Windows and the production instance is Linux, then the problem might be: Windows is not case sensitive while Linux is case sensitive, in terms of naming of file paths.

For example, a locale folder name should be:

  • zh_Hans instead of zh_hans
  • pt_BR instead of pt_br
Dzhuang
  • 1,895
  • 1
  • 14
  • 15