mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[1.10.x] Fixed #27221 -- Doc'd how to escape a percent symbol in ugettext().
Backport of b1a9041535 from master
			
			
This commit is contained in:
		| @@ -1821,6 +1821,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 |    (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. |    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 <old-string-formatting>` (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-js-code: | ||||||
|  |  | ||||||
| Creating message files from JavaScript source code | Creating message files from JavaScript source code | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user