django internationalization and translations issue

前端 未结 7 1711
傲寒
傲寒 2020-12-09 18:52

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

相关标签:
7条回答
  • 2020-12-09 19:15

    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',
    )
    
    0 讨论(0)
  • 2020-12-09 19:17

    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.

    0 讨论(0)
  • 2020-12-09 19:17

    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.

    0 讨论(0)
  • 2020-12-09 19:25

    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.

    0 讨论(0)
  • 2020-12-09 19:33

    Make sure to use ugettext_lazy and not ugettext

    0 讨论(0)
  • 2020-12-09 19:38

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

    0 讨论(0)
提交回复
热议问题