Skip to content

Commit

Permalink
Support Kurdish by hard-coding the language name
Browse files Browse the repository at this point in the history
  • Loading branch information
jnm committed Apr 20, 2017
1 parent 392769f commit 2627b4b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 43 deletions.
24 changes: 19 additions & 5 deletions kobo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
import subprocess

from django.conf import global_settings
from django.conf.global_settings import LANGUAGES as _available_langs
from django.conf.global_settings import LOGIN_URL
from django.utils.translation import get_language_info
import dj_database_url

from pymongo import MongoClient

from static_lists import NATIVE_LANGUAGE_NAMES


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
Expand Down Expand Up @@ -147,10 +148,23 @@
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/


_available_langs = dict(_available_langs)
LANGUAGES = [(lang_code, get_language_info(lang_code)['name_local'])
for lang_code in os.environ.get('DJANGO_LANGUAGE_CODES', 'en').split(' ')]
def get_native_language_name(lang_code):
try:
return get_language_info(lang_code)['name_local']
except KeyError:
pass
try:
return NATIVE_LANGUAGE_NAMES[lang_code]
except KeyError:
raise KeyError(u'Please add an entry for {} to '
u'kobo.static_lists.NATIVE_LANGUAGE_NAMES and try '
u'again.'.format(lang_code))

LANGUAGES = [
(lang_code, get_native_language_name(lang_code))
for lang_code in os.environ.get(
'DJANGO_LANGUAGE_CODES', 'en').split(' ')
]

LANGUAGE_CODE = 'en-us'

Expand Down
73 changes: 36 additions & 37 deletions kobo/static_lists.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from django.utils.translation import ugettext_lazy as _

'''
This file is a place to store static, translatable lists (or tuples!). Choice
lists for registration fields were the original application.
'''
# This file is a place to store static, translatable strings

SECTORS = (
# (value, human-readable label)
Expand Down Expand Up @@ -34,26 +31,23 @@
("Other", _("Other")),
)

'''
You might generate such a list of countries with code like this:
from __future__ import print_function
import requests
import sys
url = 'https://www.humanitarianresponse.info/api/v1.0/locations?filter[admin_level]=0'
while url:
print('Fetching', url, file=sys.stderr)
response = requests.get(url)
j = response.json()
if 'next' in j:
url = j['next']['href']
else:
url = None
for d in j['data']:
print("({}, _({}))".format(repr(d['iso3']), repr(d['label'])))
'''

# You might generate such a list of countries with code like this:
#
# from __future__ import print_function
# import requests
# import sys
#
# url = 'https://www.humanitarianresponse.info/api/v1.0/locations?filter[admin_level]=0'
# while url:
# print('Fetching', url, file=sys.stderr)
# response = requests.get(url)
# j = response.json()
# if 'next' in j:
# url = j['next']['href']
# else:
# url = None
# for d in j['data']:
# print("({}, _({}))".format(repr(d['iso3']), repr(d['label'])))
COUNTRIES = (
# (value, human-readable label)
(u'AFG', _(u'Afghanistan')),
Expand Down Expand Up @@ -308,19 +302,17 @@
(u'ZWE', _(u'Zimbabwe')),
)

'''
You might generate such a list of languages with code like this:
import requests
url = 'http://loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt'
response = requests.get(url)
for line in response.iter_lines():
# Wow, the LOC does not specify an encoding in the response!
line = line.decode(response.apparent_encoding)
fields = line.strip().split('|')
if fields[2]:
print '({}, _({})),'.format(repr(fields[2]), repr(fields[3]))
'''
# You might generate such a list of languages with code like this:
#
# import requests
# url = 'http://loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt'
# response = requests.get(url)
# for line in response.iter_lines():
# # Wow, the LOC does not specify an encoding in the response!
# line = line.decode(response.apparent_encoding)
# fields = line.strip().split('|')
# if fields[2]:
# print '({}, _({})),'.format(repr(fields[2]), repr(fields[3]))
LANGUAGES = (
# (value, human-readable label)
(u'aa', _(u'Afar')),
Expand Down Expand Up @@ -508,3 +500,10 @@
(u'za', _(u'Zhuang; Chuang')),
(u'zu', _(u'Zulu')),
)

# Django itself does not support all languages, so we cannot always rely upon
# `django.utils.translation.get_language_info()` to provide native language
# names for our translations
NATIVE_LANGUAGE_NAMES = {
u'ku': u'\u0643\u0648\u0631\u062f\u06cc',
}

0 comments on commit 2627b4b

Please sign in to comment.