forked from openSUSE/planet.opensuse.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
l10n-extract-from-templates
executable file
·52 lines (41 loc) · 1.3 KB
/
l10n-extract-from-templates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import sys, os, glob, codecs
from pprint import pprint
sys.path.insert(0, os.path.join(os.path.abspath(os.curdir), "libs", "jinja"))
from jinja2 import Environment
env = Environment(extensions=['jinja2.ext.i18n'])
out = codecs.open('./locale/planetsuse.pot', 'wb', encoding='utf8')
if False:
print >>out, u"""\
msgid ""
msgstr ""
"Project-Id-Version: 0\\n"
"Report-Msgid-Bugs-To: pascal.bleser@opensuse.org\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"""
map = {}
map_order = []
for filename in glob.glob('planetsuse/*.html'):
file = codecs.open(filename, 'rb', encoding='utf8')
content = file.read()
file.close()
ast = env.parse(content)
for (lineno, function, message) in env.extract_translations(ast):
if not message in map:
map[message] = []
map_order.append(message)
pass
map[message].append((filename, lineno))
pass
pass
for message in map_order:
location_tuples = map[message]
locations = " ".join([":".join([str(x) for x in t]) for t in location_tuples])
print >>out, u"#: " + locations
print >>out, u"msgid \"%s\"" % message.replace("\"", "\\\"")
print >>out, u"msgstr \"\""
print >>out
pass
out.close()