问题
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