本文整理汇总了Python中oslo_i18n.get_available_languages方法的典型用法代码示例。如果您正苦于以下问题:Python oslo_i18n.get_available_languages方法的具体用法?Python oslo_i18n.get_available_languages怎么用?Python oslo_i18n.get_available_languages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_i18n
的用法示例。
在下文中一共展示了oslo_i18n.get_available_languages方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_extra_lang
# 需要导入模块: import oslo_i18n [as 别名]
# 或者: from oslo_i18n import get_available_languages [as 别名]
def test_extra_lang(self):
languages = _gettextutils.get_available_languages('oslo')
languages.append(_FAKE_LANG)
self.useFixture(fixture.PrefixLazyTranslation(languages=languages))
raw_id1 = 'fake msg1'
expected_msg_en_US = ('oslo_i18n/' +
fixture.PrefixLazyTranslation._DEFAULT_LANG +
': ' + raw_id1)
expected_msg_en_ZZ = 'oslo_i18n/' + _FAKE_LANG + ': ' + raw_id1
msg1 = _(raw_id1) # noqa
self.assertEqual(languages,
_gettextutils.get_available_languages('oslo_i18n'))
self.assertEqual(languages,
oslo_i18n.get_available_languages('oslo_i18n'))
self.assertEqual(expected_msg_en_US, _translate.translate(msg1))
self.assertEqual(expected_msg_en_ZZ,
_translate.translate(msg1,
desired_locale=_FAKE_LANG))
示例2: test_best_match_language
# 需要导入模块: import oslo_i18n [as 别名]
# 或者: from oslo_i18n import get_available_languages [as 别名]
def test_best_match_language(self):
# Test that we are actually invoking language negotiation by webop
request = wsgi.Request.blank('/')
oslo_i18n.get_available_languages = mock.MagicMock()
oslo_i18n.get_available_languages.return_value = [
'known-language', 'es', 'zh']
request.headers['Accept-Language'] = 'known-language'
language = request.best_match_language()
self.assertEqual('known-language', language)
# If the Accept-Leader is an unknown language, missing or empty,
# the best match locale should be None
request.headers['Accept-Language'] = 'unknown-language'
language = request.best_match_language()
self.assertIsNone(language)
request.headers['Accept-Language'] = ''
language = request.best_match_language()
self.assertIsNone(language)
request.headers.pop('Accept-Language')
language = request.best_match_language()
self.assertIsNone(language)
示例3: test_default
# 需要导入模块: import oslo_i18n [as 别名]
# 或者: from oslo_i18n import get_available_languages [as 别名]
def test_default(self):
# Turn lazy off to check that fixture turns it on
self.useFixture(fixture.ToggleLazy(False))
self.useFixture(fixture.PrefixLazyTranslation())
self.assertTrue(_lazy.USE_LAZY)
default_lang = fixture.PrefixLazyTranslation._DEFAULT_LANG
raw_id1 = 'fake msg1'
expected_msg = 'oslo_i18n/' + default_lang + ': ' + raw_id1
msg1 = _(raw_id1) # noqa
self.assertEqual([default_lang],
_gettextutils.get_available_languages('oslo_i18n'))
self.assertEqual([default_lang],
oslo_i18n.get_available_languages('oslo_i18n'))
self.assertEqual(expected_msg, _translate.translate(msg1))
示例4: test_get_available_languages
# 需要导入模块: import oslo_i18n [as 别名]
# 或者: from oslo_i18n import get_available_languages [as 别名]
def test_get_available_languages(self):
oslo_i18n.get_available_languages('domains')
示例5: get_available_languages
# 需要导入模块: import oslo_i18n [as 别名]
# 或者: from oslo_i18n import get_available_languages [as 别名]
def get_available_languages():
return oslo_i18n.get_available_languages(DOMAIN)
示例6: get_available_languages
# 需要导入模块: import oslo_i18n [as 别名]
# 或者: from oslo_i18n import get_available_languages [as 别名]
def get_available_languages():
return oslo_i18n.get_available_languages(DOMAIN)
示例7: get_available_languages
# 需要导入模块: import oslo_i18n [as 别名]
# 或者: from oslo_i18n import get_available_languages [as 别名]
def get_available_languages():
return i18n.get_available_languages(DOMAIN)
示例8: get_available_languages
# 需要导入模块: import oslo_i18n [as 别名]
# 或者: from oslo_i18n import get_available_languages [as 别名]
def get_available_languages():
"""
返回当前可以提供翻译的语言列表
#所有的语言包在 /usr/local/lib/python2.7/dist-packages/babel/locale-data/
:return:
"""
return oslo_i18n.get_available_languages(DOMAIN)
示例9: best_match_language
# 需要导入模块: import oslo_i18n [as 别名]
# 或者: from oslo_i18n import get_available_languages [as 别名]
def best_match_language(self):
"""Determines best available locale from the Accept-Language header.
:returns: the best language match or None if the 'Accept-Language'
header was not available in the request.
"""
if not self.accept_language:
return None
all_languages = i18n.get_available_languages('tacker')
return self.accept_language.best_match(all_languages)
示例10: best_match_language
# 需要导入模块: import oslo_i18n [as 别名]
# 或者: from oslo_i18n import get_available_languages [as 别名]
def best_match_language(self):
"""Determine best available locale from the Accept-Language header.
:returns: the best language match or None if the 'Accept-Language'
header was not available in the request.
"""
if not self.accept_language:
return None
all_languages = oslo_i18n.get_available_languages('senlin')
return self.accept_language.best_match(all_languages)