Browse Source

Merge "Fix babel msgids to include tag attributes and entities" into stable/mitaka

Jenkins 2 years ago
parent
commit
f4b9e17315

+ 18
- 0
horizon/test/tests/babel_extract_angular.py View File

@@ -1,3 +1,4 @@
1
+# -*- encoding: UTF-8 -*-
1 2
 # Copyright 2015, Rackspace, US, Inc.
2 3
 #
3 4
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -170,3 +171,20 @@ class ExtractAngularTestCase(test.TestCase):
170 171
         self.assertEqual(
171 172
             [(1, 'gettext', 'hello <b>beautiful <i>world</i></b> !', [])],
172 173
             messages)
174
+
175
+    def test_nested_variations(self):
176
+        buf = StringIO(
177
+            '''
178
+            <p translate>To <a href="link">link</a> here</p>
179
+            <p translate>To <!-- a comment!! --> here</p>
180
+            <p translate>To trademark&reg; &#62; &#x3E; here</p>
181
+            '''
182
+        )
183
+        messages = list(extract_angular(buf, [], [], {}))
184
+        self.assertEqual(
185
+            [
186
+                (2, u'gettext', 'To <a href="link">link</a> here', []),
187
+                (3, u'gettext', 'To <!-- a comment!! --> here', []),
188
+                (4, u'gettext', u'To trademark® &#62; &#x3E; here', []),
189
+            ],
190
+            messages)

+ 30
- 1
horizon/utils/babel_extract_angular.py View File

@@ -1,3 +1,4 @@
1
+# -*- encoding: UTF-8 -*-
1 2
 # Copyright 2015, Rackspace, US, Inc.
2 3
 #
3 4
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -22,6 +23,16 @@ filter_regex = re.compile(
22 23
     r"""{\$\s*('([^']|\\')+'|"([^"]|\\")+")\s*\|\s*translate\s*\$}"""
23 24
 )
24 25
 
26
+# browser innerHTML decodes some html entities automatically, so when
27
+# we extract the msgid and want to match what Javascript sees, we need
28
+# to leave some entities alone, but decode all the rest. Add entries
29
+# to HTML_ENTITIES as necessary.
30
+HTML_ENTITY_PASSTHROUGH = {'amp', 'gt', 'lt'}
31
+HTML_ENTITY_DECODED = {
32
+    'reg': u'®',
33
+    'times': u'×'
34
+}
35
+
25 36
 
26 37
 class AngularGettextHTMLParser(html_parser.HTMLParser):
27 38
     """Parse HTML to find translate directives.
@@ -68,7 +79,10 @@ class AngularGettextHTMLParser(html_parser.HTMLParser):
68 79
                     if attr == 'translate-comment':
69 80
                         self.comments.append(value)
70 81
         elif self.in_translate:
71
-            self.data += '<%s>' % tag
82
+            s = tag
83
+            if attrs:
84
+                s += ' ' + ' '.join('%s="%s"' % a for a in attrs)
85
+            self.data += '<%s>' % s
72 86
             self.inner_tags.append(tag)
73 87
         else:
74 88
             for attr in attrs:
@@ -89,6 +103,21 @@ class AngularGettextHTMLParser(html_parser.HTMLParser):
89 103
                     (self.line, u'gettext', match[0][1:-1], [])
90 104
                 )
91 105
 
106
+    def handle_entityref(self, name):
107
+        if self.in_translate:
108
+            if name in HTML_ENTITY_PASSTHROUGH:
109
+                self.data += '&%s;' % name
110
+            else:
111
+                self.data += HTML_ENTITY_DECODED[name]
112
+
113
+    def handle_charref(self, name):
114
+        if self.in_translate:
115
+            self.data += '&#%s;' % name
116
+
117
+    def handle_comment(self, comment):
118
+        if self.in_translate:
119
+            self.data += '<!--%s-->' % comment
120
+
92 121
     def handle_endtag(self, tag):
93 122
         if self.in_translate:
94 123
             if len(self.inner_tags) > 0:

+ 1
- 1
openstack_dashboard/dashboards/project/static/dashboard/project/containers/create-container-modal.html View File

@@ -26,7 +26,7 @@
26 26
           <div class="form-group">
27 27
             <label class="control-label" translate>Container Access</label>
28 28
             <div>
29
-              <label for="id_public" translate>
29
+              <label for="id_public">
30 30
                 <input type="checkbox" ng-model="ctrl.model.public"
31 31
                         name="public" checked id="id_public">
32 32
                 <span translate>Public</span>

Loading…
Cancel
Save