本文整理匯總了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)