Ticket #11240: 11240-1.diff
File 11240-1.diff, 9.4 KB (added by , 13 years ago) |
---|
-
django/utils/translation/trans_real.py
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
a b 439 439 endblock_re = re.compile(r"""^\s*endblocktrans$""") 440 440 plural_re = re.compile(r"""^\s*plural$""") 441 441 constant_re = re.compile(r"""_\(((?:".*?")|(?:'.*?'))\)""") 442 one_percent_re = re.compile(r"""(?<!%)%(?!%)""") 442 443 443 444 444 445 def templatize(src, origin=None): … … 529 530 g = g.strip('"') 530 531 elif g[0] == "'": 531 532 g = g.strip("'") 533 g = one_percent_re.sub('%%', g) 532 534 if imatch.group(2): 533 535 # A context is provided 534 536 context_match = context_re.match(imatch.group(2)) -
tests/regressiontests/i18n/commands/compilation.py
diff --git a/tests/regressiontests/i18n/commands/compilation.py b/tests/regressiontests/i18n/commands/compilation.py
a b 9 9 from django.test import TestCase 10 10 11 11 12 LOCALE='es_AR'13 14 12 class MessageCompilationTests(TestCase): 15 13 16 MO_FILE='locale/%s/LC_MESSAGES/django.mo' % LOCALE17 18 14 def setUp(self): 19 15 self._cwd = os.getcwd() 20 16 self.test_dir = os.path.abspath(os.path.dirname(__file__)) … … 25 21 26 22 class PoFileTests(MessageCompilationTests): 27 23 24 LOCALE='es_AR' 25 MO_FILE='locale/%s/LC_MESSAGES/django.mo' % LOCALE 26 28 27 def test_bom_rejection(self): 29 28 os.chdir(self.test_dir) 30 # We don't use the django.core.management in trastructure (call_command()29 # We don't use the django.core.management infrastructure (call_command() 31 30 # et al) because CommandError's cause exit(1) there. We test the 32 31 # underlying compile_messages function instead 33 32 out = StringIO() 34 self.assertRaises(CommandError, compile_messages, out, locale= LOCALE)33 self.assertRaises(CommandError, compile_messages, out, locale=self.LOCALE) 35 34 self.assertFalse(os.path.exists(self.MO_FILE)) 35 36 37 class PoFileContentsTests(MessageCompilationTests): 38 39 LOCALE='de' 40 MO_FILE='locale/%s/LC_MESSAGES/django.mo' % LOCALE 41 42 def setUp(self): 43 super(PoFileContentsTests, self).setUp() 44 self.addCleanup(os.unlink, os.path.join(self.test_dir, self.MO_FILE)) 45 46 def test_percent_symbol_in_po_file(self): 47 # ticket #11240 48 os.chdir(self.test_dir) 49 # We don't use the django.core.management infrastructure (call_command() 50 # et al) because CommandError's cause exit(1) there. We test the 51 # underlying compile_messages function instead 52 out = StringIO() 53 compile_messages(out, locale=self.LOCALE) 54 self.assertTrue(os.path.exists(self.MO_FILE)) -
tests/regressiontests/i18n/commands/extraction.py
diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py
a b 31 31 os.chdir(self._cwd) 32 32 33 33 def assertMsgId(self, msgid, s, use_quotes=True): 34 q = '"' 34 35 if use_quotes: 35 36 msgid = '"%s"' % msgid 37 q = "'" 38 needle = 'msgid %s' % msgid 36 39 msgid = re.escape(msgid) 37 return self.assertTrue(re.search('^msgid %s' % msgid, s, re.MULTILINE) )40 return self.assertTrue(re.search('^msgid %s' % msgid, s, re.MULTILINE), 'Could not find %(q)s%(n)s%(q)s in generated PO file' % {'n':needle, 'q':q}) 38 41 39 42 def assertNotMsgId(self, msgid, s, use_quotes=True): 40 43 if use_quotes: … … 71 74 self.assertTrue('#. Translators: One-line translator comment #5 -- with non ASCII characters: áéíóúö' in po_contents) 72 75 self.assertTrue('#. Translators: Two-line translator comment #5 -- with non ASCII characters: áéíóúö\n#. continued here.' in po_contents) 73 76 74 def test_templatize(self): 77 def test_templatize_trans_tag(self): 78 # ticket #11240 79 os.chdir(self.test_dir) 80 management.call_command('makemessages', locale=LOCALE, verbosity=0) 81 self.assertTrue(os.path.exists(self.PO_FILE)) 82 po_contents = open(self.PO_FILE, 'r').read() 83 self.assertMsgId('Literal with a percent symbol at the end %%', po_contents) 84 self.assertMsgId('Literal with a percent %% symbol in the middle', po_contents) 85 self.assertMsgId('Completed 50%% of all the tasks', po_contents) 86 self.assertMsgId('Completed 99%% of all the tasks', po_contents) 87 self.assertMsgId("Shouldn't double escape this sequence: %% (two percent signs)", po_contents) 88 self.assertMsgId("Shouldn't double escape this sequence %% either", po_contents) 89 self.assertMsgId("Looks like a str fmt spec %%s but shouldn't be interpreted as such", po_contents) 90 self.assertMsgId("Looks like a str fmt spec %% o but shouldn't be interpreted as such", po_contents) 91 92 def test_templatize_blocktrans_tag(self): 93 # ticket #11966 75 94 os.chdir(self.test_dir) 76 95 management.call_command('makemessages', locale=LOCALE, verbosity=0) 77 96 self.assertTrue(os.path.exists(self.PO_FILE)) -
new file tests/regressiontests/i18n/commands/locale/de/LC_MESSAGES/django.po
diff --git a/tests/regressiontests/i18n/commands/locale/de/LC_MESSAGES/django.po b/tests/regressiontests/i18n/commands/locale/de/LC_MESSAGES/django.po new file mode 100644
- + 1 # SOME DESCRIPTIVE TITLE. 2 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 # This file is distributed under the same license as the PACKAGE package. 4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. 5 # 6 msgid "" 7 msgstr "" 8 "Project-Id-Version: PACKAGE VERSION\n" 9 "Report-Msgid-Bugs-To: \n" 10 "POT-Creation-Date: 2011-12-04 04:59-0600\n" 11 "PO-Revision-Date: 2011-12-04 10:03-0300\n" 12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 13 "Language-Team: LANGUAGE <LL@li.org>\n" 14 "Language: de\n" 15 "MIME-Version: 1.0\n" 16 "Content-Type: text/plain; charset=UTF-8\n" 17 "Content-Transfer-Encoding: 8bit\n" 18 "Plural-Forms: nplurals=2; plural=(n != 1)\n" 19 20 #. Translators: Django template comment for translators 21 #: templates/test.html:9 22 #, python-format 23 msgid "I think that 100%% is more that 50%% of anything." 24 msgstr "" 25 26 #: templates/test.html:10 27 #, python-format 28 msgid "I think that 100%% is more that 50%% of %(obj)s." 29 msgstr "" 30 31 #: templates/test.html:70 32 #, python-format 33 msgid "Literal with a percent symbol at the end %%" 34 msgstr "" 35 36 #: templates/test.html:71 37 #, python-format 38 msgid "Literal with a percent %% symbol in the middle" 39 msgstr "" 40 41 #: templates/test.html:72 42 #, python-format 43 msgid "Completed 50%% of all the tasks" 44 msgstr "" 45 46 #: templates/test.html:73 47 #, python-format 48 msgctxt "ctx0" 49 msgid "Completed 99%% of all the tasks" 50 msgstr "" 51 52 #: templates/test.html:74 53 #, python-format 54 msgid "Shouldn't double escape this sequence: %% (two percent signs)" 55 msgstr "" 56 57 #: templates/test.html:75 58 #, python-format 59 msgctxt "ctx1" 60 msgid "Shouldn't double escape this sequence %% either" 61 msgstr "" 62 63 #: templates/test.html:76 64 #, python-format 65 msgid "Looks like a str fmt spec %%s but shouldn't be interpreted as such" 66 msgstr "Translation of the above string" 67 68 #: templates/test.html:77 69 #, python-format 70 msgid "Looks like a str fmt spec %% o but shouldn't be interpreted as such" 71 msgstr "Translation contains %% for the above string" -
tests/regressiontests/i18n/commands/templates/test.html
diff --git a/tests/regressiontests/i18n/commands/templates/test.html b/tests/regressiontests/i18n/commands/templates/test.html
a b 65 65 {% blocktrans context "Special blocktrans context #1" %}Translatable literal #8a{% endblocktrans %} 66 66 {% blocktrans count 2 context "Special blocktrans context #2" %}Translatable literal #8b-singular{% plural %}Translatable literal #8b-plural{% endblocktrans %} 67 67 {% blocktrans context "Special blocktrans context #3" count 2 %}Translatable literal #8c-singular{% plural %}Translatable literal #8c-plural{% endblocktrans %} 68 {% blocktrans with a=1 context "Special blocktrans context #4" %}Translatable literal #8d {{ a }}{% endblocktrans %} 69 No newline at end of file 68 {% blocktrans with a=1 context "Special blocktrans context #4" %}Translatable literal #8d {{ a }}{% endblocktrans %} 69 70 {% trans "Literal with a percent symbol at the end %" %} 71 {% trans "Literal with a percent % symbol in the middle" %} 72 {% trans "Completed 50% of all the tasks" %} 73 {% trans "Completed 99% of all the tasks" context "ctx0" %} 74 {% trans "Shouldn't double escape this sequence: %% (two percent signs)" %} 75 {% trans "Shouldn't double escape this sequence %% either" context "ctx1" %} 76 {% trans "Looks like a str fmt spec %s but shouldn't be interpreted as such" %} 77 {% trans "Looks like a str fmt spec % o but shouldn't be interpreted as such" %} -
tests/regressiontests/i18n/tests.py
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
a b 31 31 CopyPluralFormsExtractorTests, NoWrapExtractorTests, 32 32 NoLocationExtractorTests) 33 33 if can_run_compilation_tests: 34 from .commands.compilation import MessageCompilationTests, PoFileTests34 from .commands.compilation import PoFileTests, PoFileContentsTests 35 35 from .contenttypes.tests import ContentTypeTests 36 36 from .forms import I18nForm, SelectDateForm, SelectDateWidget, CompanyForm 37 37 from .models import Company, TestModel