Undefined = UndefinedType()
+class FakeTranslator(object):
+ """
+ Default null translator.
+ """
+
+ def gettext(self, s):
+ return s
+
+ def ngettext(self, s, p, n):
+ if n == 1:
+ return s
+ return p
+
+
class Deferred(object):
"""
Object marking an deferred value. Deferred objects are
def get_translator(self):
"""Return the translator for i18n."""
- return lambda a, b, c: a
+ return FakeTranslator()
def pop(self):
if len(self._stack) <= 2:
' apply_filters = environment.apply_filters\n'
' call_function = environment.call_function\n'
' call_function_simple = environment.call_function_simple\n'
- ' finish_var = environment.finish_var\n'
+ ' finish_var = environment.finish_var'
]
self.indention = 1
rv = self.handle_node_list(node)
if self.require_translations:
- lines.append(' translate = context.get_translator()')
+ lines.append(
+ ' translator = context.get_translator()\n'
+ ' def translate(s, p=None, n=None, r=None):\n'
+ ' if p is None:\n'
+ ' return translator.gettext(s) % (r or {})\n'
+ ' return translator.ngettext(s, p, r[n]) % (r or {})'
+ )
lines.append(rv)
return '\n'.join(lines)
replacements = '{%s}' % ', '.join(replacements)
else:
replacements = 'None'
- if node.indicator is not None:
- indicator = 'context[\'%s\']' % node.indicator
- else:
- indicator = 'None'
- return self.indent('write(translate(%r, %r, %s) %% %s)' % (
+ return self.indent('write(translate(%r, %r, %r, %s))' % (
node.singular,
node.plural,
- indicator,
+ node.indicator,
replacements
))