#18881: tag "trans" not working with "context"
------------------------------------+--------------------------------------
     Reporter:  lanyjie             |                    Owner:  nobody
         Type:  Bug                 |                   Status:  new
    Component:  Template system     |                  Version:  1.4
     Severity:  Normal              |               Resolution:
     Keywords:  trans context i18n  |             Triage Stage:  Unreviewed
    Has patch:  0                   |      Needs documentation:  0
  Needs tests:  0                   |  Patch needs improvement:  0
Easy pickings:  0                   |                    UI/UX:  0
------------------------------------+--------------------------------------

Comment (by lanyjie):

 @julien: I looked at that code and it seems we can do the following with
 the testempt.html:
 {{{
     def test_template_message_context_extractor(self):
         """
         Ensure that message contexts are correctly extracted for the
         {% trans %} and {% blocktrans %} template tags.
         Refs #14806.
         """
         os.chdir(self.test_dir)
         management.call_command('makemessages', locale=LOCALE,
 verbosity=0)
         self.assertTrue(os.path.exists(self.PO_FILE))
         with open(self.PO_FILE, 'r') as fp:
             po_contents = fp.read()
             # {% trans %}
             self.assertTrue('msgctxt "Special trans context #1"' in
 po_contents)
             self.assertTrue("Translatable literal #7a" in po_contents)
             self.assertTrue('msgctxt "Special trans context #2"' in
 po_contents)
             self.assertTrue("Translatable literal #7b" in po_contents)
             self.assertTrue('msgctxt "Special trans context #3"' in
 po_contents)
             self.assertTrue("Translatable literal #7c" in po_contents)

             #ticket #18881, single quote context
             self.assertTrue('msgctxt "finance"' in po_contents)
             self.assertMsgId('budget', po_contents)

             #{% blocktrans %}
 }}}

 However, the call of
 {{{
     self.assertMsgId('finance', po_contents)
 }}}
 currently does NOT check for duplicate message id in the po file, which is
 not quite adequate.
 Therefore, in the same file, where assertMsgId is defined, we can  use the
 following definition instead:
 {{{
     def assertMsgId(self, msgid, s, use_quotes=True):
         q = '"'
         if use_quotes:
             msgid = '"%s"' % msgid
             q = "'"
         needle = 'msgid %s' % msgid
         msgid = re.escape(msgid)
         matches = len(re.findall('^msgid %s' % msgid, s, re.MULTILINE))
         return self.assertTrue( matches==1,
             'Could not find %(q)s%(n)s%(q)s in generated PO file' %
 {'n':needle, 'q':q} if matches==0 else
             'Found more than one occurrences of %(q)s%(n)s%(q)s in
 generated PO file' % {'n':needle, 'q':q})

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18881#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to