Add custom language for localization in Django app

瘦欲@ 提交于 2019-12-25 08:47:40

问题


adding a custom language to django

I checked this question and did all the steps mentioned in the accepted answer. After doing all when I go to /kjv/ then it redirects to /en/kjv/

Project structure:

MyProject ---------locale -------------kjv -----------------LC_MESSAGES --------------------django.mo --------------------django.po ---------myproject --------------settings.py ---------app ---------manage.py

Some one can help me to fix this?

settings.py

...

import django.conf.locale

gettext = lambda s: s

EXTRA_LANG_INFO = {
    'kjv': {
        'bidi': False,
        'code': u'kjv',
        'name': u'Kjvx',
        'name_local': u'Kjvx'
    },
}

# Add custom languages not provided by Django
LANG_INFO = dict(django.conf.locale.LANG_INFO.items() + EXTRA_LANG_INFO.items())
django.conf.locale.LANG_INFO = LANG_INFO
LANGUAGES = (
    ('hr', gettext('hr')),
    ('en', gettext('en')),
    ('de', gettext('de')),
    ('fr', gettext('fr')),
    ('kjv', gettext('kjv')),
)
...

Django-1.6.5 and all urls are wrapped in i18n_patterns.


回答1:


If anyone come to this place and facing similar issue then don't forget to update/add LOCALE_PATHS in settings.py

e.g

PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))

LOCALE_PATHS = (
    os.path.join(PROJECT_PATH, '../locale'),
)

You can point to anywhere, given they exist and have valid locale structure.



来源:https://stackoverflow.com/questions/38511925/add-custom-language-for-localization-in-django-app

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