Commits

Branko Vukelic committed 864263b

Added babel support and langauges lists

Comments (0)

Files changed (3)

dev_requirements.txt

 https://www.djangoproject.com/download/1.5a1/tarball/#egg=django
 mock==1.0.0
 coverage==3.5.3
+babel>=0.9

international/models.py

 from django.db import models
 from django.utils.translation import ugettext as _
 
+try:
+    import babel
+except ImportError:
+    babel = None
+    print "WARNING, language names will not be available"
+
+__all__ = ['countries_raw', 'countries', 'currencies', 'languages',
+           'languages_native', 'languages_english', 'Country']
 
 """Countries and currencies
 
     ('ZWD', _('ZWD - Zimbabwe Dollar')),
 )
 
-languages = (
-    ('aa': _('Afar')),
-    ('ab': _('Abkhazian')),
-    ('ae': _('Avestan')),
-    ('af': _('Afrikaans')),
-    ('ak': _('Akan')),
-    ('am': _('Amharic')),
-    ('an': _('Aragonese')),
-    ('ar': _('Arabic')),
-    ('as': _('Assamese')),
-    ('av': _('Avaric')),
-    ('ay': _('Aymara')),
-    ('az': _('Azerbaijani')),
-    ('ba': _('Bashkir')),
-    ('be': _('Belarusian')),
-    ('bg': _('Bulgarian')),
-    ('bh': _('Bihari languages')),
-    ('bi': _('Bislama')),
-    ('bm': _('Bambara')),
-    ('bn': _('Bengali')),
-    ('bo': _('Tibetan')),
-    ('br': _('Breton')),
-    ('bs': _('Bosnian')),
-    ('ca': _('Catalan')),
-    ('ca': _('Valencian')),
-    ('ce': _('Chechen')),
-    ('ch': _('Chamorro')),
-    ('co': _('Corsican')),
-    ('cr': _('Cree')),
-    ('cs': _('Czech')),
-    ('cu': _('Church Slavic')),
-    ('cu': _('Church Slavonic')),
-    ('cu': _('Old Bulgarian')),
-    ('cu': _('Old Church Slavonic')),
-    ('cu': _('Old Slavonic')),
-    ('cv': _('Chuvash')),
-    ('cy': _('Welsh')),
-    ('da': _('Danish')),
-    ('de': _('German')),
-    ('dv': _('Dhivehi')),
-    ('dv': _('Divehi')),
-    ('dv': _('Maldivian')),
-    ('dz': _('Dzongkha')),
-    ('ee': _('Ewe')),
-    ('el': _('Modern Greek (1453-)')),
-    ('en': _('English')),
-    ('eo': _('Esperanto')),
-    ('es': _('Spanish')),
-    ('es': _('Castilian')),
-    ('et': _('Estonian')),
-    ('eu': _('Basque')),
-    ('fa': _('Persian')),
-    ('ff': _('Fulah')),
-    ('fi': _('Finnish')),
-    ('fj': _('Fijian')),
-    ('fo': _('Faroese')),
-    ('fr': _('French')),
-    ('fy': _('Western Frisian')),
-    ('ga': _('Irish')),
-    ('gd': _('Scottish Gaelic')),
-    ('gd': _('Gaelic')),
-    ('gl': _('Galician')),
-    ('gn': _('Guarani')),
-    ('gu': _('Gujarati')),
-    ('gv': _('Manx')),
-    ('ha': _('Hausa')),
-    ('he': _('Hebrew')),
-    ('hi': _('Hindi')),
-    ('ho': _('Hiri Motu')),
-    ('hr': _('Croatian')),
-    ('ht': _('Haitian')),
-    ('ht': _('Haitian Creole')),
-    ('hu': _('Hungarian')),
-    ('hy': _('Armenian')),
-    ('hz': _('Herero')),
-    ('ia': _('Interlingua (International Auxiliary Language')),
-    ('id': _('Indonesian')),
-    ('ie': _('Interlingue')),
-    ('ie': _('Occidental')),
-    ('ig': _('Igbo')),
-    ('ii': _('Sichuan Yi')),
-    ('ii': _('Nuosu')),
-    ('ik': _('Inupiaq')),
-    ('in': _('Indonesian')),
-    ('io': _('Ido')),
-    ('is': _('Icelandic')),
-    ('it': _('Italian')),
-    ('iu': _('Inuktitut')),
-    ('iw': _('Hebrew')),
-    ('ja': _('Japanese')),
-    ('ji': _('Yiddish')),
-    ('jv': _('Javanese')),
-    ('jw': _('Javanese')),
-    ('ka': _('Georgian')),
-    ('kg': _('Kongo')),
-    ('ki': _('Kikuyu')),
-    ('ki': _('Gikuyu')),
-    ('kj': _('Kuanyama')),
-    ('kj': _('Kwanyama')),
-    ('kk': _('Kazakh')),
-    ('kl': _('Kalaallisut')),
-    ('kl': _('Greenlandic')),
-    ('km': _('Central Khmer')),
-    ('kn': _('Kannada')),
-    ('ko': _('Korean')),
-    ('kr': _('Kanuri')),
-    ('ks': _('Kashmiri')),
-    ('ku': _('Kurdish')),
-    ('kv': _('Komi')),
-    ('kw': _('Cornish')),
-    ('ky': _('Kirghiz')),
-    ('ky': _('Kyrgyz')),
-    ('la': _('Latin')),
-    ('lb': _('Luxembourgish')),
-    ('lb': _('Letzeburgesch')),
-    ('lg': _('Ganda')),
-    ('li': _('Limburgan')),
-    ('li': _('Limburger')),
-    ('li': _('Limburgish')),
-    ('ln': _('Lingala')),
-    ('lo': _('Lao')),
-    ('lt': _('Lithuanian')),
-    ('lu': _('Luba-Katanga')),
-    ('lv': _('Latvian')),
-    ('mg': _('Malagasy')),
-    ('mh': _('Marshallese')),
-    ('mi': _('Maori')),
-    ('mk': _('Macedonian')),
-    ('ml': _('Malayalam')),
-    ('mn': _('Mongolian')),
-    ('mo': _('Moldavian')),
-    ('mo': _('Moldovan')),
-    ('mr': _('Marathi')),
-    ('ms': _('Malay (macrolanguage)')),
-    ('mt': _('Maltese')),
-    ('my': _('Burmese')),
-    ('na': _('Nauru')),
-    ('nb': _('Norwegian Bokmål')),
-    ('nd': _('North Ndebele')),
-    ('ne': _('Nepali (macrolanguage)')),
-    ('ng': _('Ndonga')),
-    ('nl': _('Dutch')),
-    ('nl': _('Flemish')),
-    ('nn': _('Norwegian Nynorsk')),
-    ('no': _('Norwegian')),
-    ('nr': _('South Ndebele')),
-    ('nv': _('Navajo')),
-    ('nv': _('Navaho')),
-    ('ny': _('Nyanja')),
-    ('ny': _('Chewa')),
-    ('ny': _('Chichewa')),
-    ('oc': _('Occitan (post 1500)')),
-    ('oj': _('Ojibwa')),
-    ('om': _('Oromo')),
-    ('or': _('Oriya (macrolanguage)')),
-    ('os': _('Ossetian')),
-    ('os': _('Ossetic')),
-    ('pa': _('Panjabi')),
-    ('pa': _('Punjabi')),
-    ('pi': _('Pali')),
-    ('pl': _('Polish')),
-    ('ps': _('Pushto')),
-    ('ps': _('Pashto')),
-    ('pt': _('Portuguese')),
-    ('qu': _('Quechua')),
-    ('rm': _('Romansh')),
-    ('rn': _('Rundi')),
-    ('ro': _('Romanian')),
-    ('ro': _('Moldavian')),
-    ('ro': _('Moldovan')),
-    ('ru': _('Russian')),
-    ('rw': _('Kinyarwanda')),
-    ('sa': _('Sanskrit')),
-    ('sc': _('Sardinian')),
-    ('sd': _('Sindhi')),
-    ('se': _('Northern Sami')),
-    ('sg': _('Sango')),
-    ('sh': _('Serbo-Croatian')),
-    ('si': _('Sinhala')),
-    ('si': _('Sinhalese')),
-    ('sk': _('Slovak')),
-    ('sl': _('Slovenian')),
-    ('sm': _('Samoan')),
-    ('sn': _('Shona')),
-    ('so': _('Somali')),
-    ('sq': _('Albanian')),
-    ('sr': _('Serbian')),
-    ('ss': _('Swati')),
-    ('st': _('Southern Sotho')),
-    ('su': _('Sundanese')),
-    ('sv': _('Swedish')),
-    ('sw': _('Swahili (macrolanguage)')),
-    ('ta': _('Tamil')),
-    ('te': _('Telugu')),
-    ('tg': _('Tajik')),
-    ('th': _('Thai')),
-    ('ti': _('Tigrinya')),
-    ('tk': _('Turkmen')),
-    ('tl': _('Tagalog')),
-    ('tn': _('Tswana')),
-    ('to': _('Tonga (Tonga Islands)')),
-    ('tr': _('Turkish')),
-    ('ts': _('Tsonga')),
-    ('tt': _('Tatar')),
-    ('tw': _('Twi')),
-    ('ty': _('Tahitian')),
-    ('ug': _('Uighur')),
-    ('ug': _('Uyghur')),
-    ('uk': _('Ukrainian')),
-    ('ur': _('Urdu')),
-    ('uz': _('Uzbek')),
-    ('ve': _('Venda')),
-    ('vi': _('Vietnamese')),
-    ('vo': _('Volapük')),
-    ('wa': _('Walloon')),
-    ('wo': _('Wolof')),
-    ('xh': _('Xhosa')),
-    ('yi': _('Yiddish')),
-    ('yo': _('Yoruba')),
-    ('za': _('Zhuang')),
-    ('za': _('Chuang')),
-    ('zh': _('Chinese')),
-    ('zu': _('Zulu')),
-    ('en-GB-oed': _('English, Oxford English Dictionary spelling')),
-    ('no-bok': _('Norwegian Bokmal')),
-    ('no-nyn': _('Norwegian Nynorsk')),
-    ('zh-guoyu': _('Mandarin or Standard Chinese')),
-    ('zh-hakka': _('Hakka')),
-    ('zh-min': _('Min, Fuzhou, Hokkien, Amoy, or Taiwanese')),
-    ('zh-min-nan': _('Minnan, Hokkien, Amoy, Taiwanese, Southern Min, Southern')),
-    ('zh-xiang': _('Xiang or Hunanese')),
-    ('az-Arab': _('Azerbaijani in Arabic script')),
-    ('az-Cyrl': _('Azerbaijani in Cyrillic script')),
-    ('az-Latn': _('Azerbaijani in Latin script')),
-    ('be-Latn': _('Belarusian in Latin script')),
-    ('bs-Cyrl': _('Bosnian in Cyrillic script')),
-    ('bs-Latn': _('Bosnian in Latin script')),
-    ('en-boont': _('Boontling')),
-    ('en-scouse': _('Scouse')),
-    ('iu-Cans': _('Inuktitut in Canadian Aboriginal Syllabic script')),
-    ('iu-Latn': _('Inuktitut in Latin script')),
-    ('mn-Cyrl': _('Mongolian in Cyrillic script')),
-    ('mn-Mong': _('Mongolian in Mongolian script')),
-    ('sl-nedis': _('Natisone dialect, Nadiza dialect')),
-    ('sl-rozaj': _('Resian, Resianic, Rezijan')),
-    ('sr-Cyrl': _('Serbian in Cyrillic script')),
-    ('sr-Latn': _('Serbian in Latin script')),
-    ('tg-Arab': _('Tajik in Arabic script')),
-    ('tg-Cyrl': _('Tajik in Cyrillic script')),
-    ('uz-Cyrl': _('Uzbek in Cyrillic script')),
-    ('uz-Latn': _('Uzbek in Latin script')),
-    ('yi-Latn': _('Yiddish, in Latin script')),
-    ('zh-cmn': _('Mandarin Chinese')),
-    ('zh-cmn-Hans': _('Mandarin Chinese (Simplified)')),
-    ('zh-cmn-Hant': _('Mandarin Chinese (Traditional)')),
-    ('zh-gan': _('Kan or Gan')),
-    ('zh-Hans': _('Simplified Chinese')),
-    ('zh-Hans-CN': _('PRC Mainland Chinese in simplified script')),
-    ('zh-Hans-HK': _('Hong Kong Chinese in simplified script')),
-    ('zh-Hans-MO': _('Macao Chinese in simplified script')),
-    ('zh-Hans-SG': _('Singapore Chinese in simplified script')),
-    ('zh-Hans-TW': _('Taiwan Chinese in simplified script')),
-    ('zh-Hant': _('Traditional Chinese')),
-    ('zh-Hant-CN': _('PRC Mainland Chinese in traditional script')),
-    ('zh-Hant-HK': _('Hong Kong Chinese in traditional script')),
-    ('zh-Hant-MO': _('Macao Chinese in traditional script')),
-    ('zh-Hant-SG': _('Singapore Chinese in traditional script')),
-    ('zh-Hant-TW': _('Taiwan Chinese in traditional script')),
-    ('zh-wuu': _('Shanghaiese or Wu')),
-    ('zh-yue': _('Cantonese')),
-)
+languages = []
+languages_native = []
+languages_english = []
+
+if babel:
+    locales = babel.localedata.list()
+    locales.sort()
+    for l_id in locales:
+        l = babel.Locale(l_id)
+        if l.english_name:
+            languages_english.append((l_id, _(l.english_name)))
+            if l.display_name:
+                languages_native.append((l_id, l.display_name))
+                languages.append(
+                    (l_id, "%s (%s)" % (l.display_name, l.english_name))
+                )
+
 
 class Country(models.Model):
     """
+# --*-- coding: utf8 --*--
+
 from __future__ import unicode_literals
 
 from django.test import TestCase
 
-from international.models import Country
+from international.models import *
 from international.forms import *
 
+
 class CountryTestCase(TestCase):
     def setUp(self):
         self.country = Country.objects.create(code='AR', continent='SA')
     def tearDown(self):
         Country.objects.all().delete()
 
+
 class CountryFormTestCase(TestCase):
     def setUp(self):
         self.country = Country.objects.create(code='AR', continent='SA')
                             empty_label='Any currency')
         self.assertIn(('*', 'Any currency'), form.fields['currency'].choices)
 
+
+class LangTest(TestCase):
+    def test_language_list(self):
+        self.assertIn(('ja', '日本語 (Japanese)'), languages)
+
+    def test_language_native_list(self):
+        self.assertIn(('ja', '日本語'), languages_native)
+
+    def test_language_english_list(self):
+        self.assertIn(('ja', 'Japanese'), languages_english)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.