Skip to content
Myr

[svn] small changes in the i18n system of jinja

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 43aa3f7 · Browse files · 2 files+25 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+25 added−9 removed

  • other:+25 added−9 removed

2 files+25 added−9 removed

modified:jinja/translators/python.py+10 added-8 removed
225 unmodified lines
226 ' perform_test = environment.perform_test\n'227 ' apply_filters = environment.apply_filters\n'228 ' call_function = environment.call_function\n'229 ' call_function_simple = environment.call_function_simple\n'230 ' finish_var = environment.finish_var\n'230 ' finish_var = environment.finish_var'231 ]232 self.indention = 1233 rv = self.handle_node_list(node)234235 if self.require_translations:236 lines.append(' translate = context.get_translator()')236 lines.append(237 ' translator = context.get_translator()\n'238 ' def translate(s, p=None, n=None, r=None):\n'239 ' if p is None:\n'240 ' return translator.gettext(s) % (r or {})\n'241 ' return translator.ngettext(s, p, r[n]) % (r or {})'242 )243 lines.append(rv)244245 return '\n'.join(lines)246
218 unmodified lines
465 ))466 replacements = '{%s}' % ', '.join(replacements)467 else:468 replacements = 'None'463 if node.indicator is not None:464 indicator = 'context[\'%s\']' % node.indicator465 else:466 indicator = 'None'467 return self.indent('write(translate(%r, %r, %s) %% %s)' % (469 return self.indent('write(translate(%r, %r, %r, %s))' % (470 node.singular,471 node.plural,470 indicator,472 node.indicator,473 replacements474 ))475476 # -- python nodes
278 unmodified lines
modified:jinja/datastructure.py+15 added-1 removed
71 unmodified lines
7273Undefined = UndefinedType()747576class FakeTranslator(object):77 """78 Default null translator.79 """8081 def gettext(self, s):82 return s8384 def ngettext(self, s, p, n):85 if n == 1:86 return s87 return p888990class Deferred(object):91 """92 Object marking an deferred value. Deferred objects are93 objects that are called first access in the context.
33 unmodified lines
127 self.cache = {}128129 def get_translator(self):130 """Return the translator for i18n."""117 return lambda a, b, c: a131 return FakeTranslator()132133 def pop(self):134 if len(self._stack) <= 2:135 raise ValueError('cannot pop initial layer')
184 unmodified lines