def test_as_default(self): app = flask.Flask(__name__) babel_ext.Babel(app, default_locale='de_DE') domain = babel_ext.Domain(domain='test') with app.test_request_context(): assert babel_ext.gettext('first') == 'first' domain.as_default() assert babel_ext.gettext('first') == 'erste'
def test_no_formatting(self): """ Ensure we don't format strings unless a variable is passed. """ app = flask.Flask(__name__) babel_ext.Babel(app) with app.test_request_context(): assert gettext(u'Test %s') == u'Test %s' assert gettext(u'Test %(name)s', name=u'test') == u'Test test' assert gettext(u'Test %s') % 'test' == u'Test test'
def test_multiple_apps(self): app1 = flask.Flask(__name__) babel_ext.Babel(app1, default_locale='de_DE') app2 = flask.Flask(__name__) babel_ext.Babel(app2, default_locale='de_DE') with app1.test_request_context(): assert babel_ext.gettext('Yes') == 'Ja' assert 'de_DE' in app1.extensions["babel"].domain.cache with app2.test_request_context(): assert 'de_DE' not in app2.extensions["babel"].domain.cache
def test_basics(self): app = flask.Flask(__name__) babel_ext.Babel(app, default_locale='de_DE') with app.test_request_context(): assert gettext(u'Hello %(name)s!', name='Peter') == 'Hallo Peter!' assert ngettext(u'%(num)s Apple', u'%(num)s Apples', 3) == u'3 Äpfel' # noqa assert ngettext(u'%(num)s Apple', u'%(num)s Apples', 1) == u'1 Apfel' # noqa assert pgettext(u'button', u'Hello %(name)s!', name='Peter') == 'Hallo Peter!' # noqa assert pgettext(u'dialog', u'Hello %(name)s!', name='Peter') == 'Hallo Peter!' # noqa assert pgettext(u'button', u'Hello Guest!') == 'Hallo Gast!' assert npgettext(u'shop', u'%(num)s Apple', u'%(num)s Apples', 3) == u'3 Äpfel' # noqa assert npgettext(u'fruits', u'%(num)s Apple', u'%(num)s Apples', 3) == u'3 Äpfel' # noqa