当前位置: 首页>>代码示例>>Python>>正文


Python Locale.negotiate方法代码示例

本文整理汇总了Python中babel.core.Locale.negotiate方法的典型用法代码示例。如果您正苦于以下问题:Python Locale.negotiate方法的具体用法?Python Locale.negotiate怎么用?Python Locale.negotiate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在babel.core.Locale的用法示例。


在下文中一共展示了Locale.negotiate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_negotiate

# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.Locale import negotiate [as 别名]
 def test_negotiate(self):
     de_DE = Locale.negotiate(['de_DE', 'en_US'], ['de_DE', 'de_AT'])
     assert (de_DE.language, de_DE.territory) == ('de', 'DE')
     de = Locale.negotiate(['de_DE', 'en_US'], ['en', 'de'])
     assert (de.language, de.territory) == ('de', None)
     nothing = Locale.negotiate(['de_DE', 'de'], ['en_US'])
     assert nothing is None
开发者ID:adamchainz,项目名称:babel,代码行数:9,代码来源:test_core.py

示例2: negotiate

# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.Locale import negotiate [as 别名]
    def negotiate(cls, locale):
        """
        Negotiate proper RBNF rules based on global data
        item `rbnf_locales`

        Caching is not necessary the Locale object does that pretty well
        """
        loc = Locale.negotiate([str(Locale.parse(locale))], get_global('rbnf_locales'))

        print('TL', type(loc))

        return cls(loc)
开发者ID:blagasz,项目名称:babel,代码行数:14,代码来源:rbnf.py

示例3: _check_locale

# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.Locale import negotiate [as 别名]
def _check_locale():
    """ Determine locale from request if non set """
    if not request.environ.get('LOCALE'):
        accept_language = request.get_header('Accept-Language')
        if not accept_language:
            return

        accepted = []
        for language in accept_language.split(','):
            if language.split(';')[0] == language:
                accepted.append(language.strip())
            else:
                accepted.append(language.split(";")[0].strip())
        # fine tuning order of locale_q_pair according to q-value necessary?!

        lang = Locale.negotiate(accepted, [l[0] for l in LANGS])
        if lang:
            request.environ['LOCALE'] = str(lang)
开发者ID:Kadrian,项目名称:lagesonum,代码行数:20,代码来源:bottle_app.py

示例4: init_gettext

# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.Locale import negotiate [as 别名]
def init_gettext():
    locale_dir = os.path.join(basedir, 'cddagl', 'locale')
    preferred_locales = []

    selected_locale = get_config_value('locale', None)
    if selected_locale == 'None':
        selected_locale = None
    if selected_locale is not None:
        preferred_locales.append(selected_locale)

    system_locale = get_ui_locale()
    if system_locale is not None:
        preferred_locales.append(system_locale)

    if os.path.isdir(locale_dir):
        entries = scandir(locale_dir)
        for entry in entries:
            if entry.is_dir():
                available_locales.append(entry.name)

    available_locales.sort(key=lambda x: 0 if x == 'en' else 1)

    app_locale = Locale.negotiate(preferred_locales, available_locales)
    if app_locale is None:
        app_locale = 'en'
    else:
        app_locale = str(app_locale)

    try:
        t = gettext.translation('cddagl', localedir=locale_dir,
            languages=[app_locale])
        global _
        _ = t.gettext
    except FileNotFoundError as e:
        pass

    return app_locale
开发者ID:Muckevileye,项目名称:CDDA-Game-Launcher,代码行数:39,代码来源:launcher.py

示例5: test_negotiate_custom_separator

# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.Locale import negotiate [as 别名]
 def test_negotiate_custom_separator(self):
     de_DE = Locale.negotiate(['de-DE', 'de'], ['en-us', 'de-de'], sep='-')
     assert (de_DE.language, de_DE.territory) == ('de', 'DE')
开发者ID:adamchainz,项目名称:babel,代码行数:5,代码来源:test_core.py


注:本文中的babel.core.Locale.negotiate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。