Python oslo_i18n.get_available_languages() Examples

The following are 30 code examples of oslo_i18n.get_available_languages(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oslo_i18n , or try the search function .
Example #1
Source File: test_fixture.py    From oslo.i18n with Apache License 2.0 6 votes vote down vote up
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)) 
Example #2
Source File: test_wsgi.py    From tacker with Apache License 2.0 6 votes vote down vote up
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) 
Example #3
Source File: i18n.py    From masakari with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #4
Source File: i18n.py    From python-hpedockerplugin with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return i18n.get_available_languages(DOMAIN) 
Example #5
Source File: _i18n.py    From dragonflow with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #6
Source File: i18n.py    From vitrage with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #7
Source File: _i18n.py    From oslo.service with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #8
Source File: wsgi.py    From tacker with Apache License 2.0 5 votes vote down vote up
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) 
Example #9
Source File: _i18n.py    From watcher with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #10
Source File: i18n.py    From os-vif with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #11
Source File: i18n.py    From monasca-api with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #12
Source File: wsgi.py    From senlin with Apache License 2.0 5 votes vote down vote up
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) 
Example #13
Source File: i18n.py    From coriolis with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_available_languages():
    return i18n.get_available_languages(DOMAIN) 
Example #14
Source File: i18n.py    From aodh with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #15
Source File: i18n.py    From karbor with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return i18n.get_available_languages(DOMAIN) 
Example #16
Source File: _i18n.py    From kuryr with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #17
Source File: _i18n.py    From python-tackerclient with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #18
Source File: test_fixture.py    From oslo.i18n with Apache License 2.0 5 votes vote down vote up
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)) 
Example #19
Source File: i18n.py    From vdi-broker with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return i18n.get_available_languages(DOMAIN) 
Example #20
Source File: test_public_api.py    From oslo.i18n with Apache License 2.0 5 votes vote down vote up
def test_get_available_languages(self):
        oslo_i18n.get_available_languages('domains') 
Example #21
Source File: _i18n.py    From networking-sfc with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #22
Source File: i18n.py    From ec2-api with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #23
Source File: _i18n.py    From neutron-vpnaas with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #24
Source File: _i18n.py    From neutron-dynamic-routing with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #25
Source File: i18n.py    From compute-hyperv with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #26
Source File: _i18n.py    From networking-l2gw with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #27
Source File: _i18n.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
        return oslo_i18n.get_available_languages(DOMAIN) 
Example #28
Source File: _i18n.py    From networking-bgpvpn with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #29
Source File: _i18n.py    From Python-notes with MIT License 5 votes vote down vote up
def get_available_languages():
    """
    返回当前可以提供翻译的语言列表

    #所有的语言包在 /usr/local/lib/python2.7/dist-packages/babel/locale-data/
    :return:
    """
    return oslo_i18n.get_available_languages(DOMAIN) 
Example #30
Source File: _i18n.py    From networking-midonet with Apache License 2.0 5 votes vote down vote up
def get_available_languages():
    return oslo_i18n.get_available_languages(DOMAIN)