def get_available_languages(): """ 返回当前可以提供翻译的语言列表 #所有的语言包在 /usr/local/lib/python2.7/dist-packages/babel/locale-data/ :return: """ return oslo_i18n.get_available_languages(DOMAIN)
def best_match_language(req): """Determines the best available locale from the Accept-Language HTTP header passed in the request. """ if not req.accept_language: return None return req.accept_language.best_match( oslo_i18n.get_available_languages('keystone'))
def best_match_language(req): """Determines the best available locale from the Accept-Language HTTP header passed in the request. """ if not req.accept_language: return None return req.accept_language.best_match(oslo_i18n.get_available_languages("keystone"))
def best_match_language(self): """Determine the best available language for the request. :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 return self.accept_language.best_match(i18n.get_available_languages())
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('hypernet') return self.accept_language.best_match(all_languages)
def best_match_language(req): """Determine the best available locale. This returns best available locale based on the Accept-Language HTTP header passed in the request. """ if not req.accept_language: return None return req.accept_language.best_match( oslo_i18n.get_available_languages('keystone'))
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 = oslo_i18n.get_available_languages('neutron') return self.accept_language.best_match(all_languages)
def _best_match_language(): """Determine the best available locale. This returns best available locale based on the Accept-Language HTTP header passed in the request. """ if not flask.request.accept_languages: return None return flask.request.accept_languages.best_match( oslo_i18n.get_available_languages('keystone'))
def best_match_language(self): """Determine the best available language for the request. :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 return self.accept_language.best_match( i18n.get_available_languages())
def on_error(self, state, e): language = None if state.request.accept_language: language = state.request.accept_language.best_match( oslo_i18n.get_available_languages('neutron')) exc = api_common.convert_exception_to_http_exc(e, faults.FAULT_MAP, language) if hasattr(exc, 'code') and 400 <= exc.code < 500: LOG.info('%(action)s failed (client error): %(exc)s', {'action': state.request.method, 'exc': exc}) else: LOG.exception('%s failed.', state.request.method) return exc
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 = oslo_i18n.get_available_languages('neutron') best_match = self.accept_language.lookup(all_languages, default='fake_LANG') if best_match == 'fake_LANG': best_match = None return best_match
def on_error(self, state, e): language = None if state.request.accept_language: language = state.request.accept_language.best_match( oslo_i18n.get_available_languages('neutron')) exc = api_common.convert_exception_to_http_exc(e, v2base.FAULT_MAP, language) if hasattr(exc, 'code') and 400 <= exc.code < 500: LOG.info(_LI('%(action)s failed (client error): %(exc)s'), { 'action': state.request.method, 'exc': exc }) else: LOG.exception(_LE('%s failed.'), state.request.method) return exc
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))
def on_error(self, state, e): language = None if state.request.accept_language: all_languages = oslo_i18n.get_available_languages('neutron') language = state.request.accept_language.lookup( all_languages, default='fake_LANG') if language == 'fake_LANG': language = None exc = api_common.convert_exception_to_http_exc(e, faults.FAULT_MAP, language) if hasattr(exc, 'code') and 400 <= exc.code < 500: LOG.info('%(action)s failed (client error): %(exc)s', {'action': state.request.method, 'exc': exc}) else: LOG.exception('%s failed.', state.request.method) return exc
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))
def get_available_languages(): return oslo_i18n.get_available_languages(DOMAIN)
def get_available_languages(): return oslo_i18n.get_available_languages('heatclient')
def get_available_languages(): return oslo_i18n.get_available_languages('karborclient')
def get_available_languages(domain=DOMAIN): return i18n.get_available_languages(domain)
def get_available_languages(domain): """Lists the available languages for the given translation domain. :param domain: the domain to get languages for """ return oslo_i18n.get_available_languages(domain)
def test_get_available_languages(self): oslo_i18n.get_available_languages('domains')
def get_available_languages(): return oslo_i18n.get_available_languages('osvmexpireclient')