gettext translation not working on production syst

2020-03-20 02:08发布

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...

2条回答
冷血范
2楼-- · 2020-03-20 02:34

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
查看更多
Ridiculous、
3楼-- · 2020-03-20 02:40

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
查看更多
登录 后发表回答