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