Skip to content

Commit

Permalink
Fix Cadasta#1009 -- Customize list of accepted questionnaire languages (
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverroick authored and laura-barluzzi committed Mar 14, 2017
1 parent 51af604 commit 3d0ef06
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 83 deletions.
147 changes: 74 additions & 73 deletions cadasta/config/settings/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,78 @@


FORM_LANGS = {
'af': _('Afrikaans'),
'ar': _('Arabic'),
'az': _('Azerbaijani'),
'be': _('Belarusian'),
'bg': _('Bulgarian'),
'bn': _('Bengali'),
'br': _('Breton'),
'bs': _('Bosnian'),
'ca': _('Catalan'),
'cs': _('Czech'),
'cy': _('Welsh'),
'da': _('Danish'),
'de': _('German'),
'el': _('Greek'),
'en': _('English'),
'eo': _('Esperanto'),
'es': _('Spanish'),
'et': _('Estonian'),
'eu': _('Basque'),
'fa': _('Persian (Farsi)'),
'fi': _('Finnish'),
'fr': _('French'),
'fy': _('Western Frisian'),
'ga': _('Irish'),
'gd': _('Scottish Gaelic'),
'gl': _('Galician'),
'he': _('Hebrew'),
'hi': _('Hindi'),
'hr': _('Croatian'),
'hu': _('Hungarian'),
'ia': _('Interlingua'),
'id': _('Indonesian'),
'io': _('Ido'),
'is': _('Icelandic'),
'it': _('Italian'),
'ja': _('Japanese'),
'ka': _('Georgian'),
'kk': _('Kazakh'),
'km': _('Khmer'),
'kn': _('Kannada'),
'ko': _('Korean'),
'lb': _('Luxembourgish'),
'lt': _('Lithuanian'),
'lv': _('Latvian'),
'mk': _('Macedonian'),
'ml': _('Malayalam'),
'mn': _('Mongolian'),
'mr': _('Marathi'),
'my': _('Burmese'),
'nb': _('Norwegian (Bokmål)'),
'ne': _('Nepali'),
'nl': _('Dutch'),
'nn': _('Norwegian (Nynorsk)'),
'os': _('Ossetian'),
'pa': _('Eastern Punjabi'),
'pl': _('Polish'),
'pt': _('Portuguese'),
'ro': _('Romanian'),
'ru': _('Russian'),
'sk': _('Slovak'),
'sl': _('Slovene'),
'sq': _('Albanian'),
'sr': _('Serbian'),
'sv': _('Swedish'),
'sw': _('Swahili'),
'ta': _('Tamil'),
'te': _('Telugu'),
'th': _('Thai'),
'tr': _('Turkish'),
'tt': _('Tatar'),
'uk': _('Ukrainian'),
'ur': _('Urdu'),
'vi': _('Vietnamese')
'af': _("Afrikaans"),
'ar': _("Arabic"),
'az': _("Azerbaijani"),
'be': _("Belarusian"),
'bg': _("Bulgarian"),
'bn': _("Bengali"),
'br': _("Breton"),
'bs': _("Bosnian"),
'ca': _("Catalan"),
'cs': _("Czech"),
'cy': _("Welsh"),
'da': _("Danish"),
'de': _("German"),
'el': _("Greek"),
'en': _("English"),
'eo': _("Esperanto"),
'es': _("Spanish"),
'et': _("Estonian"),
'eu': _("Basque"),
'fa': _("Persian (Farsi)"),
'fi': _("Finnish"),
'fr': _("French"),
'fy': _("Western Frisian"),
'ga': _("Irish"),
'gd': _("Scottish Gaelic"),
'gl': _("Galician"),
'he': _("Hebrew"),
'hi': _("Hindi"),
'hr': _("Croatian"),
'hu': _("Hungarian"),
'ia': _("Interlingua"),
'id': _("Indonesian"),
'io': _("Ido"),
'is': _("Icelandic"),
'it': _("Italian"),
'ja': _("Japanese"),
'ka': _("Georgian"),
'kk': _("Kazakh"),
'km': _("Khmer"),
'kn': _("Kannada"),
'ko': _("Korean"),
'lb': _("Luxembourgish"),
'lt': _("Lithuanian"),
'lv': _("Latvian"),
'mk': _("Macedonian"),
'ml': _("Malayalam"),
'mn': _("Mongolian"),
'mr': _("Marathi"),
'my': _("Burmese"),
'nb': _("Norwegian (Bokmål)"),
'ne': _("Nepali"),
'nl': _("Dutch"),
'nn': _("Norwegian (Nynorsk)"),
'os': _("Ossetian"),
'pa': _("Eastern Punjabi"),
'pl': _("Polish"),
'pt': _("Portuguese"),
'ro': _("Romanian"),
'ru': _("Russian"),
'sk': _("Slovak"),
'sl': _("Slovene"),
'sq': _("Albanian"),
'sr': _("Serbian"),
'sv': _("Swedish"),
'sw': _("Swahili"),
'ta': _("Tamil"),
'te': _("Telugu"),
'th': _("Thai"),
'tr': _("Turkish"),
'tt': _("Tatar"),
'uk': _("Ukrainian"),
'ur': _("Urdu"),
'vi': _("Vietnamese"),
'kar': _("S'gaw Karen")
}
12 changes: 2 additions & 10 deletions cadasta/questionnaires/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.contrib.contenttypes.models import ContentType
from django.db import models, transaction
from django.utils.translation import ugettext as _
from django.utils.translation import get_language_info
from jsonattrs.models import Attribute, AttributeType, Schema
from pyxform.builder import create_survey_element_from_dict
from pyxform.errors import PyXFormError
Expand Down Expand Up @@ -130,15 +129,8 @@ def create_attrs_schema(project=None, dict=None, content_type=None,
)


# Python's builtin check_for_language does weird transformations of
# locale names...

def check_for_language(lang):
try:
get_language_info(lang)
return True
except:
return False
return lang in settings.FORM_LANGS.keys()


def multilingual_label_check(children):
Expand Down Expand Up @@ -167,7 +159,7 @@ def fix_languages(node):
if (isinstance(node, Element) and
node.tagName == 'translation' and node.hasAttribute('lang')):
iso_lang = node.getAttribute('lang')
local_lang = get_language_info(iso_lang)['name_local']
local_lang = settings.FORM_LANGS.get(iso_lang)
node.setAttribute('lang', local_lang)
else:
for child in node.childNodes:
Expand Down

0 comments on commit 3d0ef06

Please sign in to comment.