Exemplo n.º 1
0
def set_i18n_envvars():
    """Set the LANG/LANGUAGE environment variables if not set in case the
    current platform doesn't use them by default (OS X, Window)
    """

    if os.name == "nt":
        from quodlibet.util.winapi import GetUserDefaultUILanguage, \
            GetSystemDefaultUILanguage

        langs = listfilter(
            None,
            map(locale.windows_locale.get,
                [GetUserDefaultUILanguage(),
                 GetSystemDefaultUILanguage()]))
        if langs:
            environ.setdefault('LANG', langs[0])
            environ.setdefault('LANGUAGE', ":".join(langs))
    elif sys.platform == "darwin":
        from AppKit import NSLocale
        locale_id = NSLocale.currentLocale().localeIdentifier()
        lang = osx_locale_id_to_lang(locale_id)
        environ.setdefault('LANG', lang)

        preferred_langs = NSLocale.preferredLanguages()
        if preferred_langs:
            languages = map(bcp47_to_language, preferred_langs)
            environ.setdefault('LANGUAGE', ":".join(languages))
    else:
        return
Exemplo n.º 2
0
def set_i18n_envvars():
    """Set the LANG/LANGUAGE environment variables if not set in case the
    current platform doesn't use them by default (OS X, Window)
    """

    if os.name == "nt":
        from quodlibet.util.winapi import GetUserDefaultUILanguage, \
            GetSystemDefaultUILanguage

        langs = listfilter(None, map(locale.windows_locale.get,
                                     [GetUserDefaultUILanguage(),
                                      GetSystemDefaultUILanguage()]))
        if langs:
            environ.setdefault('LANG', langs[0])
            environ.setdefault('LANGUAGE', ":".join(langs))
    elif sys.platform == "darwin":
        from AppKit import NSLocale
        locale_id = NSLocale.currentLocale().localeIdentifier()
        lang = osx_locale_id_to_lang(locale_id)
        environ.setdefault('LANG', lang)

        preferred_langs = NSLocale.preferredLanguages()
        if preferred_langs:
            languages = map(bcp47_to_language, preferred_langs)
            environ.setdefault('LANGUAGE', ":".join(languages))
    else:
        return