comparison genshi/filters/tests/i18n.py @ 873:9786aa263217

Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
author palgarvio
date Tue, 23 Feb 2010 18:58:47 +0000
parents 7eb6f506bb54
children 1de952fd479e
comparison
equal deleted inserted replaced
872:e966d7a20d48 873:9786aa263217
928 translator = Translator(translations) 928 translator = Translator(translations)
929 translator.setup(tmpl) 929 translator.setup(tmpl)
930 self.assertEqual("""<html> 930 self.assertEqual("""<html>
931 <p>FooBars</p> 931 <p>FooBars</p>
932 <p>FooBar</p> 932 <p>FooBar</p>
933 </html>""", tmpl.generate(one=1, two=2).render())
934
935 def test_translate_i18n_choose_as_directive_singular_and_plural_with_strip(self):
936 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
937 xmlns:i18n="http://genshi.edgewall.org/i18n">
938 <i18n:choose numeral="two">
939 <p i18n:singular="" py:strip="">FooBar Singular with Strip</p>
940 <p i18n:plural="">FooBars Plural without Strip</p>
941 </i18n:choose>
942 <i18n:choose numeral="two">
943 <p i18n:singular="">FooBar singular without strip</p>
944 <p i18n:plural="" py:strip="">FooBars plural with strip</p>
945 </i18n:choose>
946 <i18n:choose numeral="one">
947 <p i18n:singular="">FooBar singular without strip</p>
948 <p i18n:plural="" py:strip="">FooBars plural with strip</p>
949 </i18n:choose>
950 <i18n:choose numeral="one">
951 <p i18n:singular="" py:strip="">FooBar singular with strip</p>
952 <p i18n:plural="">FooBars plural without strip</p>
953 </i18n:choose>
954 </html>""")
955 translations = DummyTranslations()
956 translator = Translator(translations)
957 translator.setup(tmpl)
958 self.assertEqual("""<html>
959 <p>FooBars Plural without Strip</p>
960 FooBars plural with strip
961 <p>FooBar singular without strip</p>
962 FooBar singular with strip
933 </html>""", tmpl.generate(one=1, two=2).render()) 963 </html>""", tmpl.generate(one=1, two=2).render())
934 964
935 def test_translate_i18n_choose_plural_singular_as_directive(self): 965 def test_translate_i18n_choose_plural_singular_as_directive(self):
936 # Ticket 371 966 # Ticket 371
937 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" 967 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
1435 xmlns:i18n="http://genshi.edgewall.org/i18n"> 1465 xmlns:i18n="http://genshi.edgewall.org/i18n">
1436 <div i18n:choose="two; fname, lname"> 1466 <div i18n:choose="two; fname, lname">
1437 <p i18n:singular="" py:strip="">Foo $fname $lname</p> 1467 <p i18n:singular="" py:strip="">Foo $fname $lname</p>
1438 <p i18n:plural="">Foos $fname $lname</p> 1468 <p i18n:plural="">Foos $fname $lname</p>
1439 </div> 1469 </div>
1470 <div i18n:choose="one; fname, lname">
1471 <p i18n:singular="" py:strip="">Foo $fname $lname</p>
1472 <p i18n:plural="">Foos $fname $lname</p>
1473 </div>
1440 </html>""") 1474 </html>""")
1441 translations = DummyTranslations({ 1475 translations = DummyTranslations({
1442 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', 1476 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s',
1443 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', 1477 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s',
1444 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', 1478 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s',
1446 }) 1480 })
1447 translator = Translator(translations) 1481 translator = Translator(translations)
1448 translator.setup(tmpl) 1482 translator.setup(tmpl)
1449 self.assertEqual("""<html> 1483 self.assertEqual("""<html>
1450 <div> 1484 <div>
1451 Vohs John Doe 1485 <p>Vohs John Doe</p>
1452 </div> 1486 </div>
1453 </html>""", tmpl.generate(two=2, fname='John', lname='Doe').render()) 1487 <div>
1488 Voh John Doe
1489 </div>
1490 </html>""", tmpl.generate(
1491 one=1, two=2, fname='John',lname='Doe').render())
1454 1492
1455 def test_translate_i18n_choose_and_plural_with_py_strip(self): 1493 def test_translate_i18n_choose_and_plural_with_py_strip(self):
1456 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" 1494 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
1457 xmlns:i18n="http://genshi.edgewall.org/i18n"> 1495 xmlns:i18n="http://genshi.edgewall.org/i18n">
1458 <div i18n:choose="two; fname, lname"> 1496 <div i18n:choose="two; fname, lname">
Copyright (C) 2012-2017 Edgewall Software