Django i18n: Common causes for translations not appearing

前端 未结 9 2112
心在旅途
心在旅途 2020-12-30 23:16

I am making a multilingual Django website. I created a messages file, populated and compiled it. I checked the site (the admin in this case,) in my wanted language (Hebrew)

9条回答
  •  甜味超标
    2020-12-30 23:48

    Just got hit by one. I had the locale/ directory in the root of my project, but by default Django looks for translations in the INSTALLED_APPS directories, and in the default translations. So it didn't find the translations I added. But some of my strings were in the default translations that come with Django (eg "Search") so a few strings were translated, which confused me.

    To add the directory where my translations were to the list of places that Django will look for translations, I had to set the LOCALE_PATHS setting. So in my case, where the locale/ directory and settings.py were both in the root of the django project I could put the following in settings.py:

    from os import path
    LOCALE_PATHS = (
        path.join(path.abspath(path.dirname(__file__)), 'locale'),
    )
    

提交回复
热议问题