forked from jdavid/walkhub-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgettext.py
46 lines (39 loc) · 1.39 KB
/
gettext.py
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
import os
import re
HEADER = r"""# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-07-20 17:40+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
"""
if __name__ == '__main__':
rexp = re.compile('(.*?[^a-zA-Z0-9_]|^)(t|N_)\("(.*?)"[\)|,]')
pot = open('locales/messages.pot', 'w')
pot.write(HEADER)
msgs = {}
for root, dirs, files in os.walk('js'):
for filename in files:
if filename.endswith('.js'):
filename = os.path.join(root, filename)
for line_no, line in enumerate(open(filename)):
source = '%s:%d' % (filename, line_no + 1)
for match in rexp.finditer(line):
msgs.setdefault(match.group(3), []).append(source)
for msg in sorted(msgs):
pot.write('\n')
for source in sorted(msgs[msg]):
pot.write('#: %s\n' % source)
pot.write('msgid "{}"\nmsgstr ""\n'.format(msg))