Django 1.9 sr_Latn locale doesn't work

给你一囗甜甜゛ 提交于 2020-12-30 02:57:12

问题


In Django 1.6.5 the following worked: in settings.py

LANGUAGES = (
    ('sr_Latn', 'Srpski'),
    ('en', 'English'),
)

whereas the locale folder with translation was also called sr_Latn.

With Django 1.9.2. sr_Latn is not recognized as a language code any more so I have to enter sr-latn, but then the locale folder is not found - regardless if it is called sr-latn, sr-Latn, sr_latn or sr_Latn.

LANGUAGES = (
    ('sr-latn', 'Srpski'),
    ('en', 'English'),
)

This problem is specific to Serbian-Latin only because that is the only locale to have such a funny format.


回答1:


It turns out Django devs did it right this time. The following setup worked like a charm:

Settings:

LANGUAGES = (
    ('sr-latn', 'Srpski'),
    ('en-gb', 'English'),
)

LOCALE_PATHS = (
    # translation files on the server must be in the same folder as this
    # settings file and this path must point to the translations.
    # Dev server works anyway with this path. 
    os.path.join(os.path.dirname(__file__), "locale"),
)

I have locale folder in the Project folder:

./project-folder/
    locale/
        sr_Latn/
            LC_MESSAGES/
                django.mo
                django.po
        en_GB/
            LC_MESSAGES/
                django.mo
                django.po

Everything finaly makes sense.



来源:https://stackoverflow.com/questions/35760101/django-1-9-sr-latn-locale-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!