forked from MailScanner/v4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-ms-lang-conf-format.py
62 lines (53 loc) · 2.05 KB
/
make-ms-lang-conf-format.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4
# Baruwa - Web 2.0 MailScanner front-end.
# Copyright (C) 2010-2012 Andrew Colin Kissa <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""Converts apple strings format files to MailScanner translation
files
"""
import re
import os
import sys
import codecs
from optparse import OptionParser
COMMENTS_RE = re.compile(r'/\*\s+(#.*)\s+\*/', re.U)
TRANSLATION_RE = re.compile(r'"(.+)"\s+=\s+"(.+)";', re.U)
COMMENT_RE = re.compile(r'\\"')
WRAPPED_STDOUT = codecs.getwriter('UTF-8')(sys.stdout)
if __name__ == '__main__':
# Run tings mon
usage = "usage: %prog strings file"
parser = OptionParser(usage)
_, arguments = parser.parse_args()
if len(arguments) != 1:
parser.error("Please apple strings file to process")
filename = arguments[0]
if not os.path.exists(filename):
parser.error("Strings file: %s does not exist" % filename)
sys.stdout = WRAPPED_STDOUT
with codecs.open(filename, 'r', 'utf-16') as infile:
for line in infile:
if line.startswith('/*'):
matches = COMMENTS_RE.match(line.strip())
print matches.groups()[0]
if '=' in line:
matches = TRANSLATION_RE.match(line.strip())
if matches:
opt, trans = matches.groups()
print u'%s = %s' % (opt,
COMMENT_RE.sub('"', trans))