Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add new languages into Django? My language "Uyghur" or "Uighur" is not supported in Django

Tags:

django

locale

how to add new languages into Django? My language "Uyghur" or "Uighur" is not supported in Django.

Can I add new language locale file in my project and use it? for example: zh_UG

this language is not supported in Django.

like image 352
Rehmetjan Avatar asked Oct 18 '12 03:10

Rehmetjan


People also ask

What languages does Django support?

Here, you defined the available languages (English, French, Spanish) for django-parler. You also specified English as the default language and indicated that django-parler should not hide untranslated content.

Is Django multilingual?

Django Simple Multilingual Support for models An inefficient, minimal and utterly simple approach to model translation based on foreign key relations and attribute proxying. The project code is forked from the original project by yazzgoth on Google code.

Is the Uyghur language supported in Django?

My language "Uyghur" or "Uighur" is not supported in Django - Stack Overflow how to add new languages into Django? My language "Uyghur" or "Uighur" is not supported in Django Bookmark this question. Show activity on this post. how to add new languages into Django? My language "Uyghur" or "Uighur" is not supported in Django.

Is it ‘Uyghur’ or “Uighur”?

In fact, the spelling “Uighur” suggests a different orthography in the Uyghur language itself. “I use the ‘Uyghur’ spelling because it’s the most faithful to the way the word is written in the Uyghur script today,” said Gardner Bovingdon, a professor of Uyghur studies at Indiana University.

Is there a way to get custom language in Django?

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. Show activity on this post. Show activity on this post.

What is the ISO language code of Uighur ئۇيغۇر تىلى?

ISO language code of Uighur ئۇيغۇر تىلى is 'ug'. In your settings.py: Show activity on this post. Based on laffuste's answer. First step, add language define in settings.py:


3 Answers

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
like image 155
laffuste Avatar answered Nov 16 '22 00:11

laffuste


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.

like image 21
c2j Avatar answered Nov 16 '22 01:11

c2j


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.

like image 40
Kirill Kniazev Avatar answered Nov 16 '22 01:11

Kirill Kniazev