Пример #1
0
    def get_layout_variant_description(self,
                                       layout_variant,
                                       with_lang=True,
                                       xlated=True):
        """
        Get description of the given layout-variant.

        :param layout_variant: layout-variant specification (e.g. 'cz (qwerty)')
        :type layout_variant: str
        :param with_lang: whether to include language of the layout-variant (if defined)
                          in the description or not
        :type with_lang: bool
        :param xlated: whethe to return translated or english version of the description
        :type xlated: bool
        :return: description of the layout-variant specification (e.g. 'Czech (qwerty)')
        :rtype: str

        """

        layout_info = self._layout_infos[layout_variant]

        # translate language and upcase its first letter, translate the
        # layout-variant description
        if xlated:
            lang = iutil.upcase_first_letter(
                iso_(layout_info.lang).decode("utf-8"))
            description = Xkb_(layout_info.desc).decode("utf-8")
        else:
            lang = iutil.upcase_first_letter(layout_info.lang)
            description = layout_info.desc

        if with_lang and lang and not description.startswith(lang):
            return "%s (%s)" % (lang, description)
        else:
            return description
Пример #2
0
    def get_layout_variant_description(self, layout_variant, with_lang=True, xlated=True):
        """
        Get description of the given layout-variant.

        :param layout_variant: layout-variant specification (e.g. 'cz (qwerty)')
        :type layout_variant: str
        :param with_lang: whether to include language of the layout-variant (if defined)
                          in the description or not
        :type with_lang: bool
        :param xlated: whethe to return translated or english version of the description
        :type xlated: bool
        :return: description of the layout-variant specification (e.g. 'Czech (qwerty)')
        :rtype: str

        """

        layout_info = self._layout_infos[layout_variant]

        # translate language and upcase its first letter, translate the
        # layout-variant description
        if xlated:
            lang = iutil.upcase_first_letter(iso_(layout_info.lang))
            description = Xkb_(layout_info.desc)
        else:
            lang = iutil.upcase_first_letter(layout_info.lang)
            description = layout_info.desc

        if with_lang and lang and not description.startswith(lang):
            return "%s (%s)" % (lang, description)
        else:
            return description
Пример #3
0
    def upcase_first_letter_test(self):
        """Upcasing first letter should work as expected."""

        # no change
        self.assertEqual(iutil.upcase_first_letter("Czech RePuBliC"), "Czech RePuBliC")

        # simple case
        self.assertEqual(iutil.upcase_first_letter("czech"), "Czech")

        # first letter only
        self.assertEqual(iutil.upcase_first_letter("czech republic"), "Czech republic")

        # no lowercase
        self.assertEqual(iutil.upcase_first_letter("czech Republic"), "Czech Republic")
Пример #4
0
    def upcase_first_letter_test(self):
        """Upcasing first letter should work as expected."""

        # no change
        self.assertEqual(iutil.upcase_first_letter("Czech RePuBliC"),
                         "Czech RePuBliC")

        # simple case
        self.assertEqual(iutil.upcase_first_letter("czech"), "Czech")

        # first letter only
        self.assertEqual(iutil.upcase_first_letter("czech republic"),
                         "Czech republic")

        # no lowercase
        self.assertEqual(iutil.upcase_first_letter("czech Republic"),
                         "Czech Republic")
Пример #5
0
def get_english_name(locale):
    """
    Function returning english name for the given locale.

    :param locale: locale to return english name for
    :type locale: str
    :return: english name for the locale or empty string if unknown
    :rtype: st
    :raise InvalidLocaleSpec: if an invalid locale is given (see LANGCODE_RE)

    """

    parts = parse_langcode(locale)
    if "language" not in parts:
        raise InvalidLocaleSpec("'%s' is not a valid locale" % locale)

    name = langtable.language_name(languageId=parts["language"],
                                   territoryId=parts.get("territory", ""),
                                   scriptId=parts.get("script", ""),
                                   languageIdQuery="en")

    return upcase_first_letter(name)
Пример #6
0
def get_english_name(locale):
    """
    Function returning english name for the given locale.

    :param locale: locale to return english name for
    :type locale: str
    :return: english name for the locale or empty string if unknown
    :rtype: st
    :raise InvalidLocaleSpec: if an invalid locale is given (see LANGCODE_RE)

    """

    parts = parse_langcode(locale)
    if "language" not in parts:
        raise InvalidLocaleSpec("'%s' is not a valid locale" % locale)

    name = langtable.language_name(languageId=parts["language"],
                                   territoryId=parts.get("territory", ""),
                                   scriptId=parts.get("script", ""),
                                   languageIdQuery="en")

    return upcase_first_letter(name)