예제 #1
0
파일: languages.py 프로젝트: BMeu/Aerarium
def get_language_names(translation_dir: str, with_native_names: bool = True) -> Iterable[Tuple[str, str]]:
    """
        Get a list of languages supported by the application, each with their name in the current language

        :param translation_dir: The directory within which the GetText translation folders can be found.
        :param with_native_names: If set to `True`, the languages' names will not only be given in the current language,
                                  but also in their native language.
        :return: A list of tuples, with the first element being the language code and the second one being the
                 language's name.
    """
    # The language in which the application is currently running.
    current_locale = get_current_locale()
    current_language = current_locale.language

    names = []
    languages = get_languages(translation_dir, get_default_language())
    for language in languages:
        # Get the locale for the currently looked at language.
        locale = Locale(language)

        # Get the language's name in the current language.
        name = locale.get_display_name(current_language)

        # If native names are requested, and the current language is not the one we are currently looking at,
        # determine the native name.
        if with_native_names and language != current_language:
            native_name = locale.get_display_name(language)

            name = f'{name} ({native_name})'

        names.append((language, name))

    # Sort the list of language names by their name, i.e. the second element in the tuple.
    names.sort(key=lambda x: x[1])
    return names
예제 #2
0
파일: languages.py 프로젝트: BMeu/Aerarium
def get_language_names(translation_dir: str, with_native_names: bool = True) -> Iterable[Tuple[str, str]]:
    """
        Get a list of languages supported by the application, each with their name in the current language

        :param translation_dir: The directory within which the GetText translation folders can be found.
        :param with_native_names: If set to `True`, the languages' names will not only be given in the current language,
                                  but also in their native language.
        :return: A list of tuples, with the first element being the language code and the second one being the
                 language's name.
    """

    # The language in which the application is currently running.
    current_locale = get_current_locale()
    current_language = current_locale.language

    names = []
    languages = get_languages(translation_dir, get_default_language())
    for language in languages:
        # Get the locale for the currently looked at language.
        locale = Locale(language)

        # Get the language's name in the current language.
        name = locale.get_display_name(current_language)

        # If native names are requested, and the current language is not the one we are currently looking at,
        # determine the native name.
        if with_native_names and language != current_language:
            native_name = locale.get_display_name(language)

            name = f'{name} ({native_name})'

        names.append((language, name))

    # Sort the list of language names by their name, i.e. the second element in the tuple.
    # The type ignore is needed until https://github.com/python/mypy/issues/9656 is fixed.
    names.sort(key=lambda x: x[1])  # type: ignore
    return names
예제 #3
0
 def _user_locale_name(user):
     l = Locale(user.language)
     return l.get_display_name(str(l))