Пример #1
0
 def _country_name(self, country_code) -> str:
     default_locale = 'C'
     local_locale = self.get_default_locale(country_code)
     native_name = GnomeDesktop.get_country_from_code(
         country_code, local_locale)
     if not native_name:
         return ""
     localized_name = GnomeDesktop.get_country_from_code(
         country_code, default_locale)
     if native_name == localized_name:
         return native_name
     else:
         return "{native} ({localized})".format(
             native=native_name, localized=localized_name)
Пример #2
0
    def _locale_name(self, locale_code: str) -> str:
        lang_code = self._language_from_locale(locale_code)

        if lang_code in ("zhs", "zht"):
            custom_lang_code = lang_code
            lang_code = "zh"
        else:
            custom_lang_code = None

        country_code = country_from_locale(locale_code)
        language_name_locale = GnomeDesktop.get_language_from_code(lang_code)
        language_name_native = GnomeDesktop.get_language_from_code(
            lang_code, locale_code)
        country_name_locale = GnomeDesktop.get_country_from_code(country_code)
        country_name_native = GnomeDesktop.get_country_from_code(
            country_code, locale_code)

        try:
            if (language_name_native == language_name_locale
                    and country_name_native == country_name_locale):
                return "{language} - {country}".format(
                    language=language_name_native.capitalize(),
                    country=country_name_native)

            if custom_lang_code:
                if custom_lang_code == "zhs":
                    country_name_locale = "simplified, " + country_name_locale
                else:
                    country_name_locale = "traditional, " + country_name_locale

            return "{language} - {country} " \
                   "({local_language} - {local_country})".format(
                    language=language_name_native.capitalize(),
                    country=country_name_native,
                    local_language=language_name_locale.capitalize(),
                    local_country=country_name_locale)
        except AttributeError:
            return locale_code
Пример #3
0
 def _locale_name(locale_code) -> str:
     lang_code = language_from_locale(locale_code)
     country_code = country_from_locale(locale_code)
     language_name_locale = GnomeDesktop.get_language_from_code(lang_code)
     language_name_native = GnomeDesktop.get_language_from_code(
             lang_code, locale_code)
     country_name_locale = GnomeDesktop.get_country_from_code(country_code)
     country_name_native = GnomeDesktop.get_country_from_code(
             country_code, locale_code)
     try:
         if (language_name_native == language_name_locale and
                 country_name_native == country_name_locale):
             return "{country} - {language}".format(
                     language=language_name_native.capitalize(),
                     country=country_name_native)
         else:
             return "{country} - {language} " \
                    "({local_country} - {local_language})".format(
                     language=language_name_native.capitalize(),
                     country=country_name_native,
                     local_language=language_name_locale.capitalize(),
                     local_country=country_name_locale)
     except AttributeError:
         return locale_code