示例#1
0
 def test_lazy_gettext(self):
     app = flask.Flask(__name__)
     babel.Babel(app, default_locale='de_DE')
     yes = lazy_gettext(u'Yes')
     with app.test_request_context():
         assert text_type(yes) == 'Ja'
     app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
     with app.test_request_context():
         assert text_type(yes) == 'Yes'
示例#2
0
 def test_lazy_ngettext(self):
     app = flask.Flask(__name__)
     babel.Babel(app, default_locale='de_DE')
     one_apple = lazy_ngettext(u'%(num)s Apple', u'%(num)s Apples', 1)
     with app.test_request_context():
         assert text_type(one_apple) == '1 Apfel'
     two_apples = lazy_ngettext(u'%(num)s Apple', u'%(num)s Apples', 2)
     with app.test_request_context():
         assert text_type(two_apples) == u'2 Äpfel'
示例#3
0
 def test_lazy_gettext_defaultdomain(self):
     app = flask.Flask(__name__)
     domain = babel.Domain(domain='test')
     babel.Babel(app, default_locale='de_DE', default_domain=domain)
     first = lazy_gettext('first')
     with app.test_request_context():
         assert text_type(first) == 'erste'
     app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
     with app.test_request_context():
         assert text_type(first) == 'first'
示例#4
0
 def __getattr__(self, attr):
     if attr == "__setstate__":
         raise AttributeError(attr)
     string = text_type(self)
     if hasattr(string, attr):
         return getattr(string, attr)
     raise AttributeError(attr)
示例#5
0
 def __hash__(self):
     return hash(text_type(self))
示例#6
0
 def __mod__(self, other):
     return text_type(self) % other
示例#7
0
 def __ge__(self, other):
     return text_type(self) >= other
示例#8
0
 def __html__(self):
     # https://github.com/python-babel/flask-babel/issues/121
     # This method is required; strings in source must be HTML-escaped if necessary
     return text_type(self)
示例#9
0
 def __iter__(self):
     return iter(text_type(self))
示例#10
0
 def __gt__(self, other):
     return text_type(self) > other
示例#11
0
 def __repr__(self):
     return "l'{0}'".format(text_type(self))
示例#12
0
 def __str__(self):
     return text_type(self._func(*self._args, **self._kwargs))
示例#13
0
 def __rmul__(self, other):
     return other * text_type(self)
示例#14
0
 def __lt__(self, other):
     return text_type(self) < other
示例#15
0
 def __mul__(self, other):
     return text_type(self) * other
示例#16
0
 def __add__(self, other):
     return text_type(self) + other
示例#17
0
 def __contains__(self, item):
     return item in text_type(self)
示例#18
0
 def __rmod__(self, other):
     return other + text_type(self)
示例#19
0
 def __eq__(self, other):
     return text_type(self) == other
示例#20
0
 def __len__(self):
     return len(text_type(self))
示例#21
0
 def __ne__(self, other):
     return text_type(self) != other
示例#22
0
 def __le__(self, other):
     return text_type(self) <= other
示例#23
0
 def __getitem__(self, key):
     return text_type(self)[key]