Code

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

File 4695-javascript-makemessages-fix.diff, 3.1 KB (added by ramiro, 4 years ago)

Fix by seveas plus tests

Line 
1diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
2--- a/django/core/management/commands/makemessages.py
3+++ b/django/core/management/commands/makemessages.py
4@@ -9,7 +9,7 @@
5 
6 from django.core.management.base import CommandError, BaseCommand
7 
8-pythonize_re = re.compile(r'\n\s*//')
9+pythonize_re = re.compile(r'(?:^|\n)\s*//')
10 
11 def handle_extensions(extensions=('html',)):
12     """
13diff --git a/tests/regressiontests/makemessages/__init__.py b/tests/regressiontests/makemessages/__init__.py
14new file mode 100644
15--- /dev/null
16+++ b/tests/regressiontests/makemessages/__init__.py
17@@ -0,0 +1,1 @@
18+#
19diff --git a/tests/regressiontests/makemessages/javascript.js b/tests/regressiontests/makemessages/javascript.js
20new file mode 100644
21--- /dev/null
22+++ b/tests/regressiontests/makemessages/javascript.js
23@@ -0,0 +1,4 @@
24+// '
25+gettext('This literal should be included.')
26+// '
27+gettext('This one as well.')
28diff --git a/tests/regressiontests/makemessages/locale/dummy b/tests/regressiontests/makemessages/locale/dummy
29new file mode 100644
30--- /dev/null
31+++ b/tests/regressiontests/makemessages/locale/dummy
32@@ -0,0 +1,1 @@
33+This file is her so version control systems don't delete/ignore the directory containing it.
34diff --git a/tests/regressiontests/makemessages/models.py b/tests/regressiontests/makemessages/models.py
35new file mode 100644
36--- /dev/null
37+++ b/tests/regressiontests/makemessages/models.py
38@@ -0,0 +1,1 @@
39+#
40diff --git a/tests/regressiontests/makemessages/tests.py b/tests/regressiontests/makemessages/tests.py
41new file mode 100644
42--- /dev/null
43+++ b/tests/regressiontests/makemessages/tests.py
44@@ -0,0 +1,45 @@
45+import os
46+import re
47+from django.test import TestCase
48+from django.core import management
49+
50+LOCALE='de'
51+
52+class ExtractorTests(TestCase):
53+
54+    def setUp(self):
55+        self._cwd = os.getcwd()
56+        self.test_dir = os.path.abspath(os.path.dirname(__file__))
57+
58+    def _rmrf(self, dname):
59+        if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir:
60+            return
61+        for root, dirs, files in os.walk(dname, topdown=False):
62+            for name in files:
63+                os.remove(os.path.join(root, name))
64+            for name in dirs:
65+                os.rmdir(os.path.join(root, name))
66+
67+    def tearDown(self):
68+        os.chdir(self.test_dir)
69+        try:
70+            self._rmrf('locale/%s' % LOCALE)
71+        except OSError:
72+            pass
73+        os.chdir(self._cwd)
74+
75+    def assertMsgId(self, msgid, s):
76+        return self.assert_(re.search('^msgid "%s"' % msgid, s, re.MULTILINE))
77+
78+
79+class JavascriptExtractorTests(ExtractorTests):
80+
81+    PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE
82+
83+    def test_javascript_literals(self):
84+        os.chdir(self.test_dir)
85+        management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0)
86+        self.assert_(os.path.exists(self.PO_FILE))
87+        po_contents = open(self.PO_FILE, 'r').read()
88+        self.assertMsgId('This literal should be included.', po_contents)
89+        self.assertMsgId('This one as well.', po_contents)