diff options
author | Dmitry Vasiliev <dima@hlabs.spb.ru> | 2005-05-20 07:41:14 +0000 |
---|---|---|
committer | Dmitry Vasiliev <dima@hlabs.spb.ru> | 2005-05-20 07:41:14 +0000 |
commit | 63b48759daa33b41be04ac40d81942a08f70b5de (patch) | |
tree | 1ada3ed55a183fec74e45f88e9a2a159070dff4e | |
parent | 0232530100237f8d0e00421526958556cd22574e (diff) | |
download | zope-tal-63b48759daa33b41be04ac40d81942a08f70b5de.tar.gz |
In case of tal:content, i18n:translate only MessageID/Message
objects should be translated
-rw-r--r-- | talinterpreter.py | 39 | ||||
-rw-r--r-- | tests/test_talinterpreter.py | 11 |
2 files changed, 24 insertions, 26 deletions
diff --git a/talinterpreter.py b/talinterpreter.py index 0fa1994..8cbc6b6 100644 --- a/talinterpreter.py +++ b/talinterpreter.py @@ -572,6 +572,17 @@ class TALInterpreter(object): bytecode_handlers["insertText"] = do_insertText bytecode_handlers["insertI18nText"] = do_insertText + def _writeText(self, text): + # '&' must be done first! + s = text.replace( + "&", "&").replace("<", "<").replace(">", ">") + self._stream_write(s) + i = s.rfind('\n') + if i < 0: + self.col += len(s) + else: + self.col = len(s) - (i + 1) + def do_insertText_tal(self, stuff): text = self.engine.evaluateText(stuff[0]) if text is None: @@ -586,15 +597,7 @@ class TALInterpreter(object): ' deprecated and will be removed in 3.3.' ' Use explicit i18n:translate="" instead.', DeprecationWarning) text = self.engine.translate(text) - # '&' must be done first! - s = text.replace( - "&", "&").replace("<", "<").replace(">", ">") - self._stream_write(s) - i = s.rfind('\n') - if i < 0: - self.col = self.col + len(s) - else: - self.col = len(s) - (i + 1) + self._writeText(text) def do_insertI18nText_tal(self, stuff): # TODO: Code duplication is BAD, we need to fix it later @@ -604,16 +607,9 @@ class TALInterpreter(object): if text is self.Default: self.interpret(stuff[1]) return - text = self.translate(text, text, {}) - # '&' must be done first! - s = text.replace( - "&", "&").replace("<", "<").replace(">", ">") - self._stream_write(s) - i = s.rfind('\n') - if i < 0: - self.col = self.col + len(s) - else: - self.col = len(s) - (i + 1) + if isinstance(text, (MessageID, Message)): + text = self.engine.translate(text) + self._writeText(text) def do_i18nVariable(self, stuff): varname, program, expression, structure = stuff @@ -744,7 +740,10 @@ class TALInterpreter(object): if structure is self.Default: self.interpret(block) return - text = self.translate(structure, structure, {}) + if isinstance(structure, (MessageID, Message)): + text = self.engine.translate(structure) + else: + text = unicode(structure) if not (repldict or self.strictinsert): # Take a shortcut, no error checking self.stream_write(text) diff --git a/tests/test_talinterpreter.py b/tests/test_talinterpreter.py index decb92b..271647e 100644 --- a/tests/test_talinterpreter.py +++ b/tests/test_talinterpreter.py @@ -239,7 +239,7 @@ class I18NCornerTestCaseBase(TestCaseBase): '<span i18n:translate="" tal:content="bar" i18n:name="bar_name"/>.' '</div>') self._check(program, - '<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n') + '<div>THIS IS TEXT FOR <span>BaRvAlUe</span>.</div>\n') def test_translate_static_text_as_dynamic_from_bytecode(self): program = [('version', TAL_VERSION), @@ -301,12 +301,11 @@ class I18NCornerTestCaseBase(TestCaseBase): self.interpreter() msgids = list(xlatdmn.data) msgids.sort() - self.assertEqual(2, len(msgids)) - self.assertEqual('BaRvAlUe', msgids[0][0]) - self.assertEqual('This is text for ${bar_name}.', msgids[1][0]) - self.assertEqual({'bar_name': '<span>BARVALUE</span>'}, msgids[1][1]) + self.assertEqual(1, len(msgids)) + self.assertEqual('This is text for ${bar_name}.', msgids[0][0]) + self.assertEqual({'bar_name': '<span>BaRvAlUe</span>'}, msgids[0][1]) self.assertEqual( - '<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n', + '<div>THIS IS TEXT FOR <span>BaRvAlUe</span>.</div>\n', result.getvalue()) def test_i18ntranslate_i18nname_and_attributes(self): |