Adding a new language to Django

I am trying to add site translations for several African languages ​​that Django 1.6.8 does not support. I don't need an administrator to work in these languages, but I need to support them.

My site already has working translations in 25 languages ​​from languages ​​officially supported by Django and they are divided into a subdomain, so de.mysite.com is German. I am using domain middleware to set the locale based on the subdomain, for example:

class SubDomainLanguage(object):
    def process_request(self, request):
        prefix = None
        try:
            prefix = request.META['HTTP_HOST'].split('.')[0]
            if prefix == 'no':
                prefix = 'nb'
            request.session['django_language'] = prefix
        except KeyError:
            pass
        if not prefix:
            request.session['django_language'] = 'en'

      

Various searches on the internet have taken me to a point where I feel like I am close to adding support for these languages, but visiting yo.mysite.com gives me the English version of the site, so something is missing (de.mysite.com in German language as expected).

Yoruba translations exist in locale / yo / LC_MESSAGES / django.mo and django.po and python manage.py compiled messages work fine.

Here are the related lines from my settings.py file:

from django.conf import global_settings
from django.utils.translation import gettext_noop

MIDDLEWARE_CLASSES = (
    ...
    'subdomainmiddleware.SubDomainLanguage',
    'django.middleware.locale.LocaleMiddleware',
    ...
)

global_settings.LANGUAGES += ('ak', gettext_noop('Akan'))
global_settings.LANGUAGES += ('ig', gettext_noop('Igbo'))
global_settings.LANGUAGES += ('rw', gettext_noop('Rwanda'))
global_settings.LANGUAGES += ('sn', gettext_noop('Shona'))
global_settings.LANGUAGES += ('yo', gettext_noop('Yoruba'))
global_settings.LANGUAGES += ('zu', gettext_noop('Zulu'))

EXTRA_LANG_INFO = {
    'ak': {
        'bidi': False,
        'code': 'ak',
        'name': 'Akan',
        'name_local': u'Akan'
    },
    'ig': {
        'bidi': False,
        'code': 'ig',
        'name': 'Igbo',
        'name_local': u'Asụsụ Igbo'
    },
    'rw': {
        'bidi': False,
        'code': 'rw',
        'name': 'Rwanda',
        'name_local': u'Kinyarwanda'
    },
    'sn': {
        'bidi': False,
        'code': 'sn',
        'name': 'Shona',
        'name_local': u'chiShona'
    },
    'yo': {
        'bidi': False,
        'code': 'yo',
        'name': 'Yoruba',
        'name_local': u'èdè Yorùbá'
    },
    'zu': {
        'bidi': False,
        'code': 'zu',
        'name': 'Zulu',
        'name_local': u'isiZulu'
    },
}

import django.conf.locale

LANG_INFO = dict(django.conf.locale.LANG_INFO.items() + EXTRA_LANG_INFO.items())
django.conf.locale.LANG_INFO = LANG_INFO

      

What could be missing? Or maybe there is something wrong?

+3


source to share





All Articles