#25297: makemessages doesn't detect the context of {% trans %} strings with a
filter
--------------------------------------+------------------------------------
     Reporter:  apocquet              |                    Owner:  nobody
         Type:  Bug                   |                   Status:  new
    Component:  Internationalization  |                  Version:  1.8
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by apocquet):

 I think the problem may come from the `inline_re` definition in
 django.utils.translation.trans_real . It it used by the `templatize`
 function, which it itself called from the commandline handler.

 Current:
 {{{#!python
 inline_re =
 
re.compile(r"""^\s*trans\s+((?:"[^"]*?")|(?:'[^']*?'))(\s+.*context\s+((?:"[^"]*?")|(?:'[^']*?')))?\s*""")
 }}}

 Possible correction:
 {{{#!python
 inline_re =
 
re.compile(r"""^\s*trans\s+((?:"[^"]*?")|(?:'[^']*?'))(?:\s*\|\s*[^\s:]+(?::(?:[^\s'":]+|(?:"[^"]*?")|(?:'[^']*?')))?)*(\s+.*context\s+((?:"[^"]*?")|(?:'[^']*?')))?\s*""")
 }}}

 The `(?:\s*\|\s*[^\s]+(?::(?:\s+|(?:"[^"]*?")|(?:'[^']*?'))?))*` regex
 should catch and throw away any filter. I may be wrong, I don't know the
 precise syntax of a filter name.
 The first part is quite simple and matches a `|` followed by a filter
 name. The second part (starting with `?::`) is more complex because it
 must matches filter arguments, including string literals.

 Test
 
[http://pythex.org/?regex=%5E%5Cs*trans%5Cs%2B((%3F%3A%22%5B%5E%22%5D*%3F%22)%7C(%3F%3A%27%5B%5E%27%5D*%3F%27))(%3F%3A%5Cs*%5C%7C%5Cs*%5B%5E%5Cs%3A%5D%2B(%3F%3A%3A(%3F%3A%5B%5E%5Cs%27%22%3A%5D%2B%7C(%3F%3A%22%5B%5E%22%5D*%3F%22)%7C(%3F%3A%27%5B%5E%27%5D*%3F%27)))%3F)*(%5Cs%2B.*context%5Cs%2B((%3F%3A%22%5B%5E%22%5D*%3F%22)%7C(%3F%3A%27%5B%5E%27%5D*%3F%27)))%3F%5Cs*&test_string=%20trans%20%27inactive%27%20%7C%20upper%3A%27foo%20bar%27%20context%20%27plural%27%20&ignorecase=0&multiline=0&dotall=0&verbose=0
 here].

--
Ticket URL: <https://code.djangoproject.com/ticket/25297#comment:3>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.228042622a81b2820377262530faee4c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to