コード例 #1
0
    def test_default_domain(self):
        app = flask.Flask(__name__)
        domain = babel_ext.Domain(domain='test')
        babel_ext.Babel(app, default_locale='de_DE', default_domain=domain)

        with app.test_request_context():
            assert babel_ext.gettext('first') == 'erste'
コード例 #2
0
    def test_lazy_gettext_defaultdomain(self):
        app = flask.Flask(__name__)
        domain = babel_ext.Domain(domain='test')
        babel_ext.Babel(app, default_locale='de_DE', default_domain=domain)
        first = lazy_gettext('first')
        domain_first = domain.lazy_gettext('first')

        with app.test_request_context():
            assert text_type(domain_first) == 'erste'
            assert text_type(first) == 'erste'

        app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
        with app.test_request_context():
            assert text_type(first) == 'first'
            assert text_type(domain_first) == 'first'
コード例 #3
0
    def test_lazy_pgettext(self):
        app = flask.Flask(__name__)
        domain = babel_ext.Domain(domain='messages')
        babel_ext.Babel(app, default_locale='de_DE')
        first = lazy_pgettext('button', 'Hello Guest!')
        domain_first = domain.lazy_pgettext('button', 'Hello Guest!')

        with app.test_request_context():
            assert text_type(domain_first) == 'Hallo Gast!'
            assert text_type(first) == 'Hallo Gast!'

        app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
        with app.test_request_context():
            assert text_type(first) == 'Hello Guest!'
            assert text_type(domain_first) == 'Hello Guest!'
コード例 #4
0
ファイル: tests.py プロジェクト: sh4nks/flask-babelplus
    def test_lazy_ngettext(self):
        app = flask.Flask(__name__)
        domain = babel_ext.Domain(domain='messages')
        babel_ext.Babel(app, default_locale='de_DE')

        one_apple = lazy_ngettext(u'%(num)s Apple', u'%(num)s Apples', 1)
        one_apple_d = domain.lazy_ngettext(u'%(num)s Apple', u'%(num)s Apples',
                                           1)  # noqa
        with app.test_request_context():
            assert str(one_apple) == '1 Apfel'
            assert str(one_apple_d) == '1 Apfel'

        two_apples = lazy_ngettext(u'%(num)s Apple', u'%(num)s Apples', 2)
        two_apples_d = domain.lazy_ngettext(u'%(num)s Apple',
                                            u'%(num)s Apples', 2)  # noqa
        with app.test_request_context():
            assert str(two_apples) == u'2 Äpfel'
            assert str(two_apples_d) == u'2 Äpfel'