Mercurial > genshi > genshi-test
comparison genshi/filters/tests/i18n.py @ 893:bf76a0fe20ae
i18n: Another unit test related to #380.
author | cmlenz |
---|---|
date | Wed, 21 Apr 2010 10:58:49 +0000 |
parents | 1de952fd479e |
children | 6fe4feb2635b |
comparison
equal
deleted
inserted
replaced
892:1de952fd479e | 893:bf76a0fe20ae |
---|---|
287 translator.setup(tmpl) | 287 translator.setup(tmpl) |
288 self.assertEqual(u"""<html> | 288 self.assertEqual(u"""<html> |
289 <p title="Ein hilfreicher Absatz">Siehe bitte <a href="help.html" title="Klicken für Hilfe">Hilfe</a></p> | 289 <p title="Ein hilfreicher Absatz">Siehe bitte <a href="help.html" title="Klicken für Hilfe">Hilfe</a></p> |
290 </html>""", tmpl.generate().render(encoding=None)) | 290 </html>""", tmpl.generate().render(encoding=None)) |
291 | 291 |
292 def test_extract_i18n_msg_elt_with_attributes(self): | 292 def test_extract_i18n_msg_with_dynamic_attributes(self): |
293 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
294 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
295 <p i18n:msg="" title="${_('A helpful paragraph')}"> | |
296 Please see <a href="help.html" title="${_('Click for help')}">Help</a> | |
297 </p> | |
298 </html>""") | |
299 translator = Translator() | |
300 translator.setup(tmpl) | |
301 messages = list(translator.extract(tmpl.stream)) | |
302 self.assertEqual(3, len(messages)) | |
303 self.assertEqual('A helpful paragraph', messages[0][2]) | |
304 self.assertEqual(3, messages[0][0]) | |
305 self.assertEqual('Click for help', messages[1][2]) | |
306 self.assertEqual(4, messages[1][0]) | |
307 self.assertEqual('Please see [1:Help]', messages[2][2]) | |
308 self.assertEqual(3, messages[2][0]) | |
309 | |
310 def test_translate_i18n_msg_with_dynamic_attributes(self): | |
311 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
312 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
313 <p i18n:msg="" title="${_('A helpful paragraph')}"> | |
314 Please see <a href="help.html" title="${_('Click for help')}">Help</a> | |
315 </p> | |
316 </html>""") | |
317 translator = Translator(lambda msgid: { | |
318 'A helpful paragraph': 'Ein hilfreicher Absatz', | |
319 'Click for help': u'Klicken für Hilfe', | |
320 'Please see [1:Help]': u'Siehe bitte [1:Hilfe]' | |
321 }[msgid]) | |
322 translator.setup(tmpl) | |
323 self.assertEqual(u"""<html> | |
324 <p title="Ein hilfreicher Absatz">Siehe bitte <a href="help.html" title="Klicken für Hilfe">Hilfe</a></p> | |
325 </html>""", tmpl.generate(_=translator.translate).render(encoding=None)) | |
326 | |
327 def test_extract_i18n_msg_as_element_with_attributes(self): | |
293 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | 328 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
294 xmlns:i18n="http://genshi.edgewall.org/i18n"> | 329 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
295 <i18n:msg params=""> | 330 <i18n:msg params=""> |
296 Please see <a href="help.html" title="Click for help">Help</a> | 331 Please see <a href="help.html" title="Click for help">Help</a> |
297 </i18n:msg> | 332 </i18n:msg> |
303 self.assertEqual('Click for help', messages[0][2]) | 338 self.assertEqual('Click for help', messages[0][2]) |
304 self.assertEqual(4, messages[0][0]) | 339 self.assertEqual(4, messages[0][0]) |
305 self.assertEqual('Please see [1:Help]', messages[1][2]) | 340 self.assertEqual('Please see [1:Help]', messages[1][2]) |
306 self.assertEqual(3, messages[1][0]) | 341 self.assertEqual(3, messages[1][0]) |
307 | 342 |
308 def test_translate_i18n_msg_elt_with_attributes(self): | 343 def test_translate_i18n_msg_as_element_with_attributes(self): |
309 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | 344 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
310 xmlns:i18n="http://genshi.edgewall.org/i18n"> | 345 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
311 <i18n:msg params=""> | 346 <i18n:msg params=""> |
312 Please see <a href="help.html" title="Click for help">Help</a> | 347 Please see <a href="help.html" title="Click for help">Help</a> |
313 </i18n:msg> | 348 </i18n:msg> |