diff options
| author | Doug Beck <doug@douglasbeck.com> | 2015-04-15 17:01:11 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-08-12 10:23:34 -0400 |
| commit | b7508896fbe19ec2cdeb81565cd587091b6b68d0 (patch) | |
| tree | 5efb501dcc753cdaf1314ba826ca59cd44c4297b /django/utils | |
| parent | d772d812cf583e0f99e21850f26addf1d59bfa35 (diff) | |
Fixed #24257 -- Corrected i18n handling of percent signs.
Refactored tests to use a sample project.
Updated extraction:
* Removed special handling of single percent signs.
* When extracting messages from template text, doubled all percent signs
so they are not interpreted by gettext as string format flags. All
strings extracted by gettext, if containing a percent sign, will now
be labeled "#, python-format".
Updated translation:
* Used "%%" for "%" in template text before calling gettext.
* Updated {% trans %} rendering to restore "%" from "%%".
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/translation/trans_real.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index 8a2527022d..e05b5613a5 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -534,7 +534,6 @@ block_re = re.compile(r"""^\s*blocktrans(\s+.*context\s+((?:"[^"]*?")|(?:'[^']*? endblock_re = re.compile(r"""^\s*endblocktrans$""") plural_re = re.compile(r"""^\s*plural$""") constant_re = re.compile(r"""_\(((?:".*?")|(?:'.*?'))\)""") -one_percent_re = re.compile(r"""(?<!%)%(?!%)""") def templatize(src, origin=None): @@ -631,7 +630,7 @@ def templatize(src, origin=None): else: singular.append('%%(%s)s' % t.contents) elif t.token_type == TOKEN_TEXT: - contents = one_percent_re.sub('%%', t.contents) + contents = t.contents.replace('%', '%%') if inplural: plural.append(contents) else: @@ -667,7 +666,7 @@ def templatize(src, origin=None): g = g.strip('"') elif g[0] == "'": g = g.strip("'") - g = one_percent_re.sub('%%', g) + g = g.replace('%', '%%') if imatch.group(2): # A context is provided context_match = context_re.match(imatch.group(2)) |
