Ticket #11240: 11240-1.diff

File 11240-1.diff, 9.4 KB (added by Ramiro Morales, 12 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  
    439439endblock_re = re.compile(r"""^\s*endblocktrans$""")
    440440plural_re = re.compile(r"""^\s*plural$""")
    441441constant_re = re.compile(r"""_\(((?:".*?")|(?:'.*?'))\)""")
     442one_percent_re = re.compile(r"""(?<!%)%(?!%)""")
    442443
    443444
    444445def templatize(src, origin=None):
     
    529530                        g = g.strip('"')
    530531                    elif g[0] == "'":
    531532                        g = g.strip("'")
     533                    g = one_percent_re.sub('%%', g)
    532534                    if imatch.group(2):
    533535                        # A context is provided
    534536                        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  
    99from django.test import TestCase
    1010
    1111
    12 LOCALE='es_AR'
    13 
    1412class MessageCompilationTests(TestCase):
    1513
    16     MO_FILE='locale/%s/LC_MESSAGES/django.mo' % LOCALE
    17 
    1814    def setUp(self):
    1915        self._cwd = os.getcwd()
    2016        self.test_dir = os.path.abspath(os.path.dirname(__file__))
     
    2521
    2622class PoFileTests(MessageCompilationTests):
    2723
     24    LOCALE='es_AR'
     25    MO_FILE='locale/%s/LC_MESSAGES/django.mo' % LOCALE
     26
    2827    def test_bom_rejection(self):
    2928        os.chdir(self.test_dir)
    30         # We don't use the django.core.management intrastructure (call_command()
     29        # We don't use the django.core.management infrastructure (call_command()
    3130        # et al) because CommandError's cause exit(1) there. We test the
    3231        # underlying compile_messages function instead
    3332        out = StringIO()
    34         self.assertRaises(CommandError, compile_messages, out, locale=LOCALE)
     33        self.assertRaises(CommandError, compile_messages, out, locale=self.LOCALE)
    3534        self.assertFalse(os.path.exists(self.MO_FILE))
     35
     36
     37class 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  
    3131        os.chdir(self._cwd)
    3232
    3333    def assertMsgId(self, msgid, s, use_quotes=True):
     34        q = '"'
    3435        if use_quotes:
    3536            msgid = '"%s"' % msgid
     37            q = "'"
     38        needle = 'msgid %s' % msgid
    3639        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})
    3841
    3942    def assertNotMsgId(self, msgid, s, use_quotes=True):
    4043        if use_quotes:
     
    7174        self.assertTrue('#. Translators: One-line translator comment #5 -- with non ASCII characters: áéíóúö' in po_contents)
    7275        self.assertTrue('#. Translators: Two-line translator comment #5 -- with non ASCII characters: áéíóúö\n#. continued here.' in po_contents)
    7376
    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
    7594        os.chdir(self.test_dir)
    7695        management.call_command('makemessages', locale=LOCALE, verbosity=0)
    7796        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#
     6msgid ""
     7msgstr ""
     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
     23msgid "I think that 100%% is more that 50%% of anything."
     24msgstr ""
     25
     26#: templates/test.html:10
     27#, python-format
     28msgid "I think that 100%% is more that 50%% of %(obj)s."
     29msgstr ""
     30
     31#: templates/test.html:70
     32#, python-format
     33msgid "Literal with a percent symbol at the end %%"
     34msgstr ""
     35
     36#: templates/test.html:71
     37#, python-format
     38msgid "Literal with a percent %% symbol in the middle"
     39msgstr ""
     40
     41#: templates/test.html:72
     42#, python-format
     43msgid "Completed 50%% of all the tasks"
     44msgstr ""
     45
     46#: templates/test.html:73
     47#, python-format
     48msgctxt "ctx0"
     49msgid "Completed 99%% of all the tasks"
     50msgstr ""
     51
     52#: templates/test.html:74
     53#, python-format
     54msgid "Shouldn't double escape this sequence: %% (two percent signs)"
     55msgstr ""
     56
     57#: templates/test.html:75
     58#, python-format
     59msgctxt "ctx1"
     60msgid "Shouldn't double escape this sequence %% either"
     61msgstr ""
     62
     63#: templates/test.html:76
     64#, python-format
     65msgid "Looks like a str fmt spec %%s but shouldn't be interpreted as such"
     66msgstr "Translation of the above string"
     67
     68#: templates/test.html:77
     69#, python-format
     70msgid "Looks like a str fmt spec %% o but shouldn't be interpreted as such"
     71msgstr "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  
    6565{% blocktrans context "Special blocktrans context #1" %}Translatable literal #8a{% endblocktrans %}
    6666{% blocktrans count 2 context "Special blocktrans context #2" %}Translatable literal #8b-singular{% plural %}Translatable literal #8b-plural{% endblocktrans %}
    6767{% 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  
    3131        CopyPluralFormsExtractorTests, NoWrapExtractorTests,
    3232        NoLocationExtractorTests)
    3333if can_run_compilation_tests:
    34     from .commands.compilation import MessageCompilationTests, PoFileTests
     34    from .commands.compilation import PoFileTests, PoFileContentsTests
    3535from .contenttypes.tests import ContentTypeTests
    3636from .forms import I18nForm, SelectDateForm, SelectDateWidget, CompanyForm
    3737from .models import Company, TestModel
Back to Top