4
# Copyright (C) 2000, 2003 Free Software Foundation.
5
# Copyright (C) 2000, 2001 Eazel, Inc
6
# Copyright (C) 2004 Bastian Blank <bblank@thinkmo.de>
8
# Intltool is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU General Public License
10
# version 2 published by the Free Software Foundation.
12
# Intltool is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
import os, re, string, sys, warnings
24
def print_translation(lang, file, a, b):
25
if lang == 'en' and not b:
26
b = a # no translation means use orig string
28
a = re.sub("'", r"\'", a)
29
b = re.sub("'", r"\'", b)
30
file.write("'''%s''':\n" % a)
31
file.write("'''%s''',\n" % b)
33
def unescape_one_sequence(match):
34
sequence = match.group(1)
44
def unescape_po_string(string):
45
return re.sub(r'(\\.)', unescape_one_sequence, string)
47
def do(lang, infile, outfile):
56
for i in infile.readlines():
59
if re.match(r'^msgstr', i):
63
match = re.match(r'"(\S+):\s+(.*)\\n"', i)
65
header[match.group(1)] = match.group(2)
66
if re.match('^\s*$', i):
71
match = re.match(r'.*charset=([-a-z0-9]+)', header['Content-Type'])
73
raise ValueError, "Please make the charset lowercase."
74
encoding = match.group(1)
77
direction = header['X-Direction']
79
warnings.warn("%s.po don't provide information about the direction, use default ('ltr')" % lang, stacklevel=2)
84
'language': header['X-Language'],
85
'elanguage': header['X-Language-in-English'],
87
'maintainer': header['Last-Translator'],
88
'direction': direction,
89
'wikimarkup': header.get('X-HasWikiMarkup', False),
92
outfile.write('''# -*- coding: %(encoding)s -*-
93
# Text translations for %(language)s (%(lang)s).
94
# Automatically generated - DO NOT EDIT, edit %(lang)s.po instead!
96
'language': """%(language)s""",
97
'elanguage': """%(elanguage)s""",
98
'maintainer': """%(maintainer)s""",
99
'encoding': '%(encoding)s',
100
'direction': '%(direction)s',
101
'wikimarkup': %(wikimarkup)s,
108
for i in infile.readlines():
109
if re.match(r'^#, fuzzy', i):
112
match = re.match(r'^msgid "((\\.|[^\\])*)"', i)
115
print_translation(lang, outfile, msgid, msgstr)
122
msgid = unescape_po_string(match.group(1));
127
match = re.match(r'^msgstr "((\\.|[^\\])*)"', i)
129
msgstr = unescape_po_string(match.group(1));
133
match = re.match(r'^"((\\.|[^\\])*)"', i)
136
msgid += unescape_po_string(match.group(1))
138
msgstr += unescape_po_string(match.group(1))
141
print_translation(lang, outfile, msgid, msgstr)
146
for i in sys.argv[1:]:
148
infilename = "%s.po" % lang
149
outfilename = "%s.py" % lang
150
infile = file(infilename, "r")
151
outfile = file(outfilename, "w")
153
do(lang, infile, outfile)
155
os.unlink(outfilename)
158
if __name__ == "__main__":