Ticket #4695: 4695-javascript-makemessages-fix.diff

File 4695-javascript-makemessages-fix.diff, 3.1 KB (added by Ramiro Morales, 15 years ago)

Fix by seveas plus tests

  • django/core/management/commands/makemessages.py

    diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
    a b  
    99
    1010from django.core.management.base import CommandError, BaseCommand
    1111
    12 pythonize_re = re.compile(r'\n\s*//')
     12pythonize_re = re.compile(r'(?:^|\n)\s*//')
    1313
    1414def handle_extensions(extensions=('html',)):
    1515    """
  • new file tests/regressiontests/makemessages/__init__.py

    diff --git a/tests/regressiontests/makemessages/__init__.py b/tests/regressiontests/makemessages/__init__.py
    new file mode 100644
    - +  
     1#
  • new file tests/regressiontests/makemessages/javascript.js

    diff --git a/tests/regressiontests/makemessages/javascript.js b/tests/regressiontests/makemessages/javascript.js
    new file mode 100644
    - +  
     1// '
     2gettext('This literal should be included.')
     3// '
     4gettext('This one as well.')
  • new file tests/regressiontests/makemessages/locale/dummy

    diff --git a/tests/regressiontests/makemessages/locale/dummy b/tests/regressiontests/makemessages/locale/dummy
    new file mode 100644
    - +  
     1This file is her so version control systems don't delete/ignore the directory containing it.
  • new file tests/regressiontests/makemessages/models.py

    diff --git a/tests/regressiontests/makemessages/models.py b/tests/regressiontests/makemessages/models.py
    new file mode 100644
    - +  
     1#
  • new file tests/regressiontests/makemessages/tests.py

    diff --git a/tests/regressiontests/makemessages/tests.py b/tests/regressiontests/makemessages/tests.py
    new file mode 100644
    - +  
     1import os
     2import re
     3from django.test import TestCase
     4from django.core import management
     5
     6LOCALE='de'
     7
     8class ExtractorTests(TestCase):
     9
     10    def setUp(self):
     11        self._cwd = os.getcwd()
     12        self.test_dir = os.path.abspath(os.path.dirname(__file__))
     13
     14    def _rmrf(self, dname):
     15        if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir:
     16            return
     17        for root, dirs, files in os.walk(dname, topdown=False):
     18            for name in files:
     19                os.remove(os.path.join(root, name))
     20            for name in dirs:
     21                os.rmdir(os.path.join(root, name))
     22
     23    def tearDown(self):
     24        os.chdir(self.test_dir)
     25        try:
     26            self._rmrf('locale/%s' % LOCALE)
     27        except OSError:
     28            pass
     29        os.chdir(self._cwd)
     30
     31    def assertMsgId(self, msgid, s):
     32        return self.assert_(re.search('^msgid "%s"' % msgid, s, re.MULTILINE))
     33
     34
     35class JavascriptExtractorTests(ExtractorTests):
     36
     37    PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE
     38
     39    def test_javascript_literals(self):
     40        os.chdir(self.test_dir)
     41        management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0)
     42        self.assert_(os.path.exists(self.PO_FILE))
     43        po_contents = open(self.PO_FILE, 'r').read()
     44        self.assertMsgId('This literal should be included.', po_contents)
     45        self.assertMsgId('This one as well.', po_contents)
Back to Top