Beispiel #1
0
def test_language_display_name(english):
    english.fullname = ""
    english.save()

    # as fullname is not set - this should default to the pycountry name
    assert (
        english.name
        == get_language_iso_fullname(english.code))

    # lets give english a custom name in db
    english.fullname = "English (bristol twang)"
    english.save()

    # as we are translating to server lang, we use lang.fullname
    # and not the one from pycountry/iso translation
    assert (
        english.name
        == english.fullname)

    with translation.override("fr"):
        # now request lang has changed (and != server lang)
        # so we get the translated name
        assert (
            english.name
            == site_languages.get().capitalize(
                tr_lang(get_language_iso_fullname(english.code))))

    with translation.override("en-GB"):
        # as request lang is also a dialect of english
        # it uses the lang.fullname
        assert (
            english.name
            == english.fullname)
Beispiel #2
0
 def localised_languages(self, langs):
     matches = False
     if self.request_lang:
         server_code = language_code.get()(settings.LANGUAGE_CODE)
         request_code = language_code.get()(self.request_lang)
         matches = server_code.matches(request_code)
     if matches:
         trans_func = lambda code, name: name
     else:
         trans_func = lambda code, name: self.capitalize(
             tr_lang(get_language_iso_fullname(code) or name))
     return {code: trans_func(code, name) for code, name in langs}
Beispiel #3
0
 def name(self):
     """localised ISO name for the language or fullname
     if request lang == server lang, and fullname is set. Uses code
     as the ultimate fallback
     """
     site_langs = site_languages.get()
     server_code = language_code.get()(settings.LANGUAGE_CODE)
     request_code = language_code.get()(translation.get_language())
     use_db_name = (not translation.get_language() or
                    (self.fullname and server_code.matches(request_code)))
     if use_db_name:
         return self.fullname
     iso_name = get_language_iso_fullname(self.code) or self.fullname
     return (site_langs.capitalize(tr_lang(iso_name))
             if iso_name else self.code)
Beispiel #4
0
 def localised_languages(self, langs):
     matches = False
     if self.request_lang:
         server_code = language_code.get()(settings.LANGUAGE_CODE)
         request_code = language_code.get()(self.request_lang)
         matches = server_code.matches(request_code)
     if matches:
         trans_func = lambda code, name: name
     else:
         trans_func = lambda code, name: self.capitalize(
             tr_lang(
                 get_language_iso_fullname(code)
                 or name))
     return {
         code: trans_func(code, name)
         for code, name
         in langs}
Beispiel #5
0
def test_language_iso_fullname():
    """Test language ISO fullnames."""
    assert data.get_language_iso_fullname("af") == 'Afrikaans'
    assert data.get_language_iso_fullname("cak") == 'Kaqchikel'
    assert data.get_language_iso_fullname("en_ZA") == 'English (South Africa)'
    assert data.get_language_iso_fullname("pt") == 'Portuguese'
    assert data.get_language_iso_fullname("pt_PT") == 'Portuguese (Portugal)'
    assert data.get_language_iso_fullname("pt_BR") == 'Portuguese (Brazil)'
    assert data.get_language_iso_fullname("pt_br") == 'Portuguese (Brazil)'
    assert data.get_language_iso_fullname("pt-BR") == 'Portuguese (Brazil)'
    assert data.get_language_iso_fullname("pt-br") == 'Portuguese (Brazil)'
    assert data.get_language_iso_fullname("ca") == 'Catalan'
    assert data.get_language_iso_fullname("ca@valencia") == ''
    assert data.get_language_iso_fullname("") == ''
    assert data.get_language_iso_fullname("z") == ''
    assert data.get_language_iso_fullname("zzz") == ''
    assert data.get_language_iso_fullname("zzzz") == ''
    assert data.get_language_iso_fullname("zz_BB") == ''
    assert data.get_language_iso_fullname("zz-BB") == ''
    assert data.get_language_iso_fullname("zzz_BBB") == ''
    assert data.get_language_iso_fullname("zzz_BBB") == ''
Beispiel #6
0
def test_language_iso_fullname():
    """Test language ISO fullnames."""
    assert data.get_language_iso_fullname("af") == "Afrikaans"
    assert data.get_language_iso_fullname("cak") == "Kaqchikel"
    assert data.get_language_iso_fullname("en_ZA") == "English (South Africa)"
    assert data.get_language_iso_fullname("pt") == "Portuguese"
    assert data.get_language_iso_fullname("pt_PT") == "Portuguese (Portugal)"
    assert data.get_language_iso_fullname("pt_BR") == "Portuguese (Brazil)"
    assert data.get_language_iso_fullname("pt_br") == "Portuguese (Brazil)"
    assert data.get_language_iso_fullname("pt-BR") == "Portuguese (Brazil)"
    assert data.get_language_iso_fullname("pt-br") == "Portuguese (Brazil)"
    assert data.get_language_iso_fullname("ca") == "Catalan"
    assert data.get_language_iso_fullname("ca@valencia") == ""
    assert data.get_language_iso_fullname("") == ""
    assert data.get_language_iso_fullname("z") == ""
    assert data.get_language_iso_fullname("zzz") == ""
    assert data.get_language_iso_fullname("zzzz") == ""
    assert data.get_language_iso_fullname("zz_BB") == ""
    assert data.get_language_iso_fullname("zz-BB") == ""
    assert data.get_language_iso_fullname("zzz_BBB") == ""
    assert data.get_language_iso_fullname("zzz_BBB") == ""
Beispiel #7
0
 def localised_lang_name(self, code, name):
     return self.capitalize(tr_lang(
         get_language_iso_fullname(code) or name))
Beispiel #8
0
def test_language_iso_fullname():
    """Test language ISO fullnames."""
    assert data.get_language_iso_fullname("af") == u'Afrikaans'
    assert data.get_language_iso_fullname("cak") == u'Kaqchikel'
    assert data.get_language_iso_fullname("en_ZA") == u'English (South Africa)'
    assert data.get_language_iso_fullname("pt") == u'Portuguese'
    assert data.get_language_iso_fullname("pt_PT") == u'Portuguese (Portugal)'
    assert data.get_language_iso_fullname("pt_BR") == u'Portuguese (Brazil)'
    assert data.get_language_iso_fullname("pt_br") == u'Portuguese (Brazil)'
    assert data.get_language_iso_fullname("pt-BR") == u'Portuguese (Brazil)'
    assert data.get_language_iso_fullname("pt-br") == u'Portuguese (Brazil)'
    assert data.get_language_iso_fullname("ca") == u'Catalan'
    assert data.get_language_iso_fullname("ca@valencia") == u''
    assert data.get_language_iso_fullname("") == u''
    assert data.get_language_iso_fullname("z") == u''
    assert data.get_language_iso_fullname("zzz") == u''
    assert data.get_language_iso_fullname("zzzz") == u''
    assert data.get_language_iso_fullname("zz_BB") == u''
    assert data.get_language_iso_fullname("zz-BB") == u''
    assert data.get_language_iso_fullname("zzz_BBB") == u''
    assert data.get_language_iso_fullname("zzz_BBB") == u''