31👍
Add a non available language to your Django app
ISO language code of Uighur ئۇيغۇر تىلى is ‘ug’.
In your settings.py:
from django.conf import global_settings
gettext_noop = lambda s: s
LANGUAGES = (
('ug', gettext_noop('Uighur')),
)
EXTRA_LANG_INFO = {
'ug': {
'bidi': True, # right-to-left
'code': 'ug',
'name': 'Uighur',
'name_local': u'\u0626\u06C7\u064A\u063A\u06C7\u0631 \u062A\u0649\u0644\u0649', #unicode codepoints here
},
}
# Add custom languages not provided by Django
import django.conf.locale
LANG_INFO = dict(django.conf.locale.LANG_INFO, **EXTRA_LANG_INFO)
django.conf.locale.LANG_INFO = LANG_INFO
# Languages using BiDi (right-to-left) layout
LANGUAGES_BIDI = global_settings.LANGUAGES_BIDI + ["ug"]
And:
manage.py makemessages -l ug
manage.py compilemessages
12👍
Based on laffuste’s answer.
First step, add language define in settings.py:
EXTRA_LANG_INFO = {
'ms': {
'bidi': False, # right-to-left
'code': 'ms',
'name': 'Bahasa Melayu',
'name_local': u'Bahasa Melayu', #unicode codepoints here
},
}
# Add custom languages not provided by Django
import django.conf.locale
from django.conf import global_settings
LANG_INFO = dict(django.conf.locale.LANG_INFO.items() + EXTRA_LANG_INFO.items())
django.conf.locale.LANG_INFO = LANG_INFO
# Languages using BiDi (right-to-left) layout
global_settings.LANGUAGES = global_settings.LANGUAGES + (("ms",'Bahasa Melayu'),)
Second step, Add locale in settings.py:
import os
PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))
LOCALE_PATHS = (
os.path.join(PACKAGE_ROOT, 'locale'),
)
Third step, Add locale defines in locale directory.
- [Django]-Django.db.utils.ProgrammingError: relation "bot_trade" does not exist
- [Django]-AccessDenied when calling the CreateMultipartUpload operation in Django using django-storages and boto3
- [Django]-Create a field whose value is a calculation of other fields' values
4👍
If someone encounters this, and will use the accepted answer (also check the comments on it) and still will have a redirect to /en/ instead of extra language – you need to create the .mo file for that locale. At least a dummy one.
Django checks if language is valid by checking if it can load the .mo file. There is no issue for standard languages because Django is shipped with a bunch of them, but for your custom language it doesn’t exists.
I hope that will save your time.
- [Django]-AccessDenied when calling the CreateMultipartUpload operation in Django using django-storages and boto3
- [Django]-Django-rest-framework returning 403 response on POST, PUT, DELETE despite AllowAny permissions
- [Django]-Filtering using viewsets in django rest framework
2👍
in your settings.py add
gettext = lambda s: s LANGUAGES = ( ('zh_UG', gettext('Uyghur')), ('en', gettext('English')), ) USE_I18N = True
run
manage.py makemessages -l zh_UG
to create language files
- [Django]-Django apps aren't loaded yet when using asgi
- [Django]-In django, how do I sort a model on a field and then get the last item?
- [Django]-Django composite unique on multiple model fields
1👍
# add Kyrgyz lang
###########################################################
from django.conf import global_settings
gettext = lambda s: s
LANGUAGES = (
('ru', gettext('Russia')),
('ky', gettext('Kyrgyz')),
)
EXTRA_LANG_INFO = {
'ky': {
'bidi': False,
'code': 'ky',
'name': 'Kyrgyz',
'name_local': u"Кыргызча",
},
}
import django.conf.locale
from django.conf import global_settings
import django.conf.locale
LANG_INFO = dict(django.conf.locale.LANG_INFO, **EXTRA_LANG_INFO)
django.conf.locale.LANG_INFO = LANG_INFO
global_settings.LANGUAGES = global_settings.LANGUAGES + [("ky", 'Кыргызча')]
import os
PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
###########################################################
- [Django]-Create a field whose value is a calculation of other fields' values
- [Django]-Sending post data from angularjs to django as JSON and not as raw content
- [Django]-Django: For Loop to Iterate Form Fields
0👍
Just wanted to add that you need to run below commands despite whether you have added some translation to the files or not:
python manage.py makemessages -l tj
python manage.py compilemessages
Note that tj here is the new added language
- [Django]-Django models avoid duplicates
- [Django]-Django apps aren't loaded yet when using asgi
- [Django]-What does 'many = True' do in Django Rest FrameWork?
- [Django]-How to produce a 303 Http Response in Django?
- [Django]-Serializer call is showing an TypeError: Object of type 'ListSerializer' is not JSON serializable?
- [Django]-Django-taggit – how do I display the tags related to each record