From b1a9041535db5d03dab7f205669f0ab7a47de854 Mon Sep 17 00:00:00 2001 From: Henry Dang Date: Wed, 9 Nov 2016 22:22:56 -0500 Subject: [PATCH] Fixed #27221 -- Doc'd how to escape a percent symbol in ugettext(). --- docs/topics/i18n/translation.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt index c960f21b84..22d3d10de3 100644 --- a/docs/topics/i18n/translation.txt +++ b/docs/topics/i18n/translation.txt @@ -1792,6 +1792,31 @@ That's it. Your translations are ready for use. (Byte Order Mark) so if your text editor adds such marks to the beginning of files by default then you will need to reconfigure it. +Troubleshooting: ``ugettext()`` incorrectly detects ``python-format`` in strings with percent signs +--------------------------------------------------------------------------------------------------- + +In some cases, such as strings with a percent sign followed by a space and a +:ref:`string conversion type ` (e.g. +``_("10% interest")``), :func:`~django.utils.translation.ugettext` incorrectly +flags strings with ``python-format``. + +If you try to compile message files with incorrectly flagged strings, you'll +get an error message like ``number of format specifications in 'msgid' and +'msgstr' does not match`` or ``'msgstr' is not a valid Python format string, +unlike 'msgid'``. + +To workaround this, you can escape percent signs by adding a second percent +sign:: + + from django.utils.translation import ugettext as _ + output = _("10%% interest) + +Or you can use ``no-python-format`` so that all percent signs are treated as +literals:: + + # xgettext:no-python-format + output = _("10% interest) + .. _creating-message-files-from-js-code: Creating message files from JavaScript source code