#371 closed defect (fixed)
i18n:plural and i18n:singular don't work as element directives
Reported by: | cboos | Owned by: | cmlenz |
---|---|---|---|
Priority: | minor | Milestone: | 0.6 |
Component: | Internationalization | Version: | devel |
Keywords: | Cc: | cboos |
Description
Not sure if this is already supposed to work, but it doesn't yet.
I think the following should be supported in the future:
-
genshi/filters/tests/i18n.py
932 932 <p>FooBar</p> 933 933 </html>""", tmpl.generate(one=1, two=2).render()) 934 934 935 def test_translate_i18n_choose_plural_singular_as_directive(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 <i18n:singular>FooBar</i18n:singular> 940 <i18n:plural>FooBars</i18n:plural> 941 </i18n:choose> 942 <i18n:choose numeral="one"> 943 <i18n:singular>FooBar</i18n:singular> 944 <i18n:plural>FooBars</i18n:plural> 945 </i18n:choose> 946 </html>""") 947 translations = DummyTranslations({ 948 ('FooBar', 0): 'FuBar', 949 ('FooBars', 1): 'FuBars', 950 'FooBar': 'FuBar', 951 'FooBars': 'FuBars', 952 }) 953 translator = Translator(translations) 954 translator.setup(tmpl) 955 self.assertEqual("""<html> 956 FuBars 957 FuBar 958 </html>""", tmpl.generate(one=1, two=2).render()) 959 935 960 def test_translate_i18n_choose_as_attribute_with_params(self): 936 961 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" 937 962 xmlns:i18n="http://genshi.edgewall.org/i18n">
Attachments (1)
Change History (9)
comment:1 Changed 15 years ago by cboos
comment:2 Changed 15 years ago by palgarvio
- Milestone changed from 0.7 to 0.6
- Status changed from new to assigned
- Version changed from 0.5.1 to devel
Thanks for the report. I'm trying to fix this(both issues).
comment:3 Changed 15 years ago by palgarvio
The py:strip issue is now handled:
-
genshi/filters/tests/i18n.py
932 932 <p>FooBar</p> 933 933 </html>""", tmpl.generate(one=1, two=2).render()) 934 934 935 def test_translate_i18n_choose_plural_singular_as_directive(self): 936 # Ticket 371 937 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" 938 xmlns:i18n="http://genshi.edgewall.org/i18n"> 939 <i18n:choose numeral="two"> 940 <i18n:singular>FooBar</i18n:singular> 941 <i18n:plural>FooBars</i18n:plural> 942 </i18n:choose> 943 <i18n:choose numeral="one"> 944 <i18n:singular>FooBar</i18n:singular> 945 <i18n:plural>FooBars</i18n:plural> 946 </i18n:choose> 947 </html>""") 948 translations = DummyTranslations({ 949 ('FooBar', 0): 'FuBar', 950 ('FooBars', 1): 'FuBars', 951 'FooBar': 'FuBar', 952 'FooBars': 'FuBars', 953 }) 954 translator = Translator(translations) 955 translator.setup(tmpl) 956 self.assertEqual("""<html> 957 FuBars 958 FuBar 959 </html>""", tmpl.generate(one=1, two=2).render()) 960 935 961 def test_translate_i18n_choose_as_attribute_with_params(self): 936 962 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" 937 963 xmlns:i18n="http://genshi.edgewall.org/i18n"> … … 1403 1429 <p>Vohs John Doe</p> 1404 1430 </div> 1405 1431 </html>""", tmpl.generate(two=2, fname='John', lname='Doe').render()) 1432 1433 def test_translate_i18n_choose_and_singular_with_py_strip(self): 1434 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" 1435 xmlns:i18n="http://genshi.edgewall.org/i18n"> 1436 <div i18n:choose="two; fname, lname"> 1437 <p i18n:singular="" py:strip="">Foo $fname $lname</p> 1438 <p i18n:plural="">Foos $fname $lname</p> 1439 </div> 1440 </html>""") 1441 translations = DummyTranslations({ 1442 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', 1443 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', 1444 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', 1445 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', 1446 }) 1447 translator = Translator(translations) 1448 translator.setup(tmpl) 1449 self.assertEqual("""<html> 1450 <div> 1451 Vohs John Doe 1452 </div> 1453 </html>""", tmpl.generate(two=2, fname='John', lname='Doe').render()) 1454 1455 def test_translate_i18n_choose_and_plural_with_py_strip(self): 1456 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" 1457 xmlns:i18n="http://genshi.edgewall.org/i18n"> 1458 <div i18n:choose="two; fname, lname"> 1459 <p i18n:singular="" py:strip="">Foo $fname $lname</p> 1460 <p i18n:plural="">Foos $fname $lname</p> 1461 </div> 1462 </html>""") 1463 translations = DummyTranslations({ 1464 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', 1465 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', 1466 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', 1467 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', 1468 }) 1469 translator = Translator(translations) 1470 translator.setup(tmpl) 1471 self.assertEqual("""<html> 1472 <div> 1473 Voh John Doe 1474 </div> 1475 </html>""", tmpl.generate(two=1, fname='John', lname='Doe').render()) 1406 1476 1407 1477 def test_extract_i18n_msg_with_py_strip(self): 1408 1478 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" -
genshi/filters/i18n.py
330 330 for kind, event, pos in stream: 331 331 if kind is SUB: 332 332 subdirectives, substream = event 333 strip_directive_present = [] 334 for idx, subdirective in enumerate(subdirectives): 335 if isinstance(subdirective, StripDirective): 336 # XXX: Any strip directive should be applied AFTER the 337 # event's have been translated and singular or plural 338 # form has been chosen. So, by having py:strip on 339 # an i18n:singular element is as if i18n:plural had it 340 # too. 341 strip_directive_present.append(subdirectives.pop(idx)) 333 342 if isinstance(subdirectives[0], 334 343 SingularDirective) and not singular_stream: 335 344 # Apply directives to update context 336 345 singular_stream = list(_apply_directives(substream, 337 346 subdirectives, 338 347 ctxt, vars)) 348 if strip_directive_present: 349 singular_stream = list( 350 _apply_directives(singular_stream, 351 strip_directive_present, 352 ctxt, vars) 353 ) 339 354 new_stream.append((MSGBUF, (), ('', -1))) # msgbuf place holder 340 355 singular_msgbuf = ctxt.get('_i18n.choose.SingularDirective') 341 356 elif isinstance(subdirectives[0],
comment:4 Changed 15 years ago by palgarvio
- Owner changed from palgarvio to cmlenz
- Status changed from assigned to new
Since I don't have the required permissions on trunk, I'm reassigning to cmlenz and adding the needed patch.
Changed 15 years ago by palgarvio
comment:5 Changed 15 years ago by palgarvio
- Resolution set to fixed
- Status changed from new to closed
Fixed in [1094].
comment:6 Changed 15 years ago by cboos
Seems I still have some trouble with Trac and the following patch:
-
trac/ticket/templates/ticket.html
diff --git a/trac/ticket/templates/ticket.html b/trac/ticket/templates/ticket.html
a b 252 252 </py:if> 253 253 <py:if test="change_replies"> 254 254 <i18n:choose numeral="len(change_replies)"> 255 <span i18n:singular="" >follow-up:</span>256 <span i18n:plural="" >follow-ups:</span>255 <span i18n:singular="" py:strip="">follow-up:</span> 256 <span i18n:plural="" py:strip="">follow-ups:</span> 257 257 </i18n:choose> 258 258 <py:for each="reply in change_replies"> 259 259 ${commentref('↓ ', reply)}
(applies on top of [T9233]).
comment:7 Changed 15 years ago by cboos
Scratch that, I must have goofed somewhere :-)
comment:8 Changed 15 years ago by palgarvio
Some more stripping issues were resolved in [1096].
Note: See
TracTickets for help on using
tickets.
Note that using something like <span i18n:singular="" py:strip="">...</span> won't work either, as apparently the py:strip removes the element before the i18n filter gets a chance to see it.