Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from jon301/master

Improve parsing
  • Loading branch information...
commit 73ae0bf90b47a0cdbd0df5eba81a7973baf686f0 2 parents 78bd5d1 + b90b257
@sebest authored
Showing with 40 additions and 13 deletions.
  1. +1 −1  setup.py
  2. +31 −0 test.html
  3. +8 −12 underscore.py
View
2  setup.py
@@ -8,4 +8,4 @@
underscore = underscore:babel_extract
"""
)
-
+
View
31 test.html
@@ -0,0 +1,31 @@
+<h1>i18n test</h1>
+<div>
+
+ <%
+ var myHash = {
+ a: $._('key 1'),
+ b: true ? $._('key 2 : voicé$ i ma\' trad2') : $._('key 3'),
+ c: { d: $._('key 4'), e: $._('key 5'), f: $.i18n.sprintf($.i18n.ngettext('key 6 : i have %1$d bird', 'key 6 : i have %1$d birds', 1), 1) }
+ };
+ var myArray = [$._('key 7'), $._('key 8')];
+ %>
+
+ <p>There is a <%= $._('key 9') %> and also a <%= $._('key 10') %></p>
+
+ <%= false || $._('key 11') %>
+
+ <%= $._('key 12') %><br />
+
+ <%= $.i18n.sprintf($.i18n.ngettext('key 13 : i have %1$d dog', 'key 13 : i have %1$d dogs', 1), 1) %><br />
+</div>
+<ul class="nav">
+ <!-- <li><a href="#dashboard">Dashboard</a></li> -->
+ <li class="dropdown">
+ <ul class="dropdown-menu">
+ <li><a href="#"><%= $._('key 14') %></a></li>
+ <li><a href="#"><%= $._('key 15') %></a><a href="#"><%= $.i18n.sprintf($.i18n.ngettext('key 16 : i have %1$d cat', 'key 16 : i have %1$d cats', 1), 1) %></a><a href="#"><%= $._('key 17') %></a></li>
+ <li><a href="#"><% var titi = $._('key 18') %><%= $._('key 19') %></a></li>
+ </ul>
+ </li>
+</ul>
+
View
20 underscore.py
@@ -4,18 +4,14 @@ def parse(fileobj):
line_nb = 0
for line in fileobj:
line_nb += 1
- m = re.match('.*<%=?\s+(?P<js>.*)\s+%>.*', line)
- if m:
- js = m.group('js')
- m = re.match('^\$\._\((?:[\'"])(?P<string>.*)(?:[\'"])\)$', js)
- if m:
- yield line_nb, 'gettext', m.group('string')
- continue
- m = re.match('^\$.*\.ngettext\((?:[\'"])(?P<string1>.*)(?:[\'"]), (?:[\'"])(?P<string2>.*)(?:[\'"]), .*\)$', js)
- if m:
- yield line_nb, 'ngettext', m.groups()
- continue
+ m = re.findall('\$\._\([\'"](.*?)[\'"]\)', line)
+ for res in m:
+ yield line_nb, 'gettext', res
+
+ m = re.search('\$.*\.ngettext\((?:[\'"])(?P<string1>.*)(?:[\'"]),[ ]*(?:[\'"])(?P<string2>.*)(?:[\'"]),.*\)', line)
+ if m:
+ yield line_nb, 'ngettext', m.groups()
def babel_extract(fileobj, keywords, comment_tags, options):
"""Extract messages from XXX files.
@@ -34,6 +30,6 @@ def babel_extract(fileobj, keywords, comment_tags, options):
yield i[0], i[1], i[2], []
if __name__ == '__main__':
- fileobj = open('/home/jtrang/webapps/cloudui2/app/templates/test.html')
+ fileobj = open('./test.html')
for i in parse(fileobj):
print i
Please sign in to comment.
Something went wrong with that request. Please try again.