Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #4695 - Worked around a problem of xgettext ignoring so…

…me translation strings in JavaScript files. Thanks, Ramiro Morales.

Backport of r12441.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12451 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6a3c9159338055339f64e73de39598d26e5656c8 1 parent a1ecd07
Jannis Leidel authored February 16, 2010
2  django/core/management/commands/makemessages.py
@@ -18,7 +18,7 @@
18 18
 # still sensible for us to use it, since subprocess didn't exist in 2.3.
19 19
 warnings.filterwarnings('ignore', category=DeprecationWarning, message=r'os\.popen3')
20 20
 
21  
-pythonize_re = re.compile(r'\n\s*//')
  21
+pythonize_re = re.compile(r'(?:^|\n)\s*//')
22 22
 
23 23
 def handle_extensions(extensions=('html',)):
24 24
     """
0  tests/regressiontests/makemessages/__init__.py
No changes.
4  tests/regressiontests/makemessages/javascript.js
... ...
@@ -0,0 +1,4 @@
  1
+// '
  2
+gettext('This literal should be included.')
  3
+// '
  4
+gettext('This one as well.')
0  tests/regressiontests/makemessages/locale/dummy
No changes.
0  tests/regressiontests/makemessages/models.py
No changes.
42  tests/regressiontests/makemessages/tests.py
... ...
@@ -0,0 +1,42 @@
  1
+import os
  2
+import re
  3
+import shutil
  4
+from django.test import TestCase
  5
+from django.core import management
  6
+
  7
+LOCALE='de'
  8
+
  9
+class ExtractorTests(TestCase):
  10
+
  11
+    def setUp(self):
  12
+        self._cwd = os.getcwd()
  13
+        self.test_dir = os.path.abspath(os.path.dirname(__file__))
  14
+
  15
+    def _rmrf(self, dname):
  16
+        if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir:
  17
+            return
  18
+        shutil.rmtree(dname)
  19
+
  20
+    def tearDown(self):
  21
+        os.chdir(self.test_dir)
  22
+        try:
  23
+            self._rmrf('locale/%s' % LOCALE)
  24
+        except OSError:
  25
+            pass
  26
+        os.chdir(self._cwd)
  27
+
  28
+    def assertMsgId(self, msgid, s):
  29
+        return self.assert_(re.search('^msgid "%s"' % msgid, s, re.MULTILINE))
  30
+
  31
+
  32
+class JavascriptExtractorTests(ExtractorTests):
  33
+
  34
+    PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE
  35
+
  36
+    def test_javascript_literals(self):
  37
+        os.chdir(self.test_dir)
  38
+        management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0)
  39
+        self.assert_(os.path.exists(self.PO_FILE))
  40
+        po_contents = open(self.PO_FILE, 'r').read()
  41
+        self.assertMsgId('This literal should be included.', po_contents)
  42
+        self.assertMsgId('This one as well.', po_contents)

0 notes on commit 6a3c915

Please sign in to comment.
Something went wrong with that request. Please try again.