##// END OF EJS Templates
translation: fix wrong argument call on request
marcink -
r2353:363cf393 default
parent child Browse files
Show More
@@ -1,66 +1,66 b''
1 1 # Copyright (C) 2016-2017 RhodeCode GmbH
2 2 #
3 3 # This program is free software: you can redistribute it and/or modify
4 4 # it under the terms of the GNU Affero General Public License, version 3
5 5 # (only), as published by the Free Software Foundation.
6 6 #
7 7 # This program is distributed in the hope that it will be useful,
8 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 # GNU General Public License for more details.
11 11 #
12 12 # You should have received a copy of the GNU Affero General Public License
13 13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 14 #
15 15 # This program is dual-licensed. If you wish to learn more about the
16 16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18 18
19 19 from pyramid.i18n import TranslationStringFactory, TranslationString
20 20
21 21 # Create a translation string factory for the 'rhodecode' domain.
22 22 from pyramid.threadlocal import get_current_request
23 23
24 24 _ = TranslationStringFactory('rhodecode')
25 25
26 26 temp_translation_factory = _
27 27
28 28
29 29 class _LazyString(object):
30 30 def __init__(self, *args, **kw):
31 31 self.args = args
32 32 self.kw = kw
33 33
34 34 def eval(self):
35 35 req = get_current_request()
36 36 translator = _
37 37 if req:
38 translator = req.translator
38 translator = req.translate
39 39 return translator(*self.args, **self.kw)
40 40
41 41 def __unicode__(self):
42 42 return unicode(self.eval())
43 43
44 44 def __str__(self):
45 45 return self.eval()
46 46
47 47 def __repr__(self):
48 48 return self.__str__()
49 49
50 50 def __mod__(self, other):
51 51 return self.eval() % other
52 52
53 53 def format(self, *args):
54 54 return self.eval().format(*args)
55 55
56 56
57 57 def lazy_ugettext(*args, **kw):
58 58 """ Lazily evaluated version of _() """
59 59 return _LazyString(*args, **kw)
60 60
61 61
62 62 def _pluralize(msgid1, msgid2, n, mapping=None):
63 63 if n == 1:
64 64 return _(msgid1, mapping=mapping)
65 65 else:
66 66 return _(msgid2, mapping=mapping)
General Comments 0
You need to be logged in to leave comments. Login now