2 # -*- coding: utf-8 -*-
9 translations
= {'cz_reduced': [('\\200', u
'á'),
33 'cz': [('\\200', u
'ě'),
64 'de': [('\\200', u
'Ä'),
72 'es': [('\\200', u
'Ñ'),
75 'fi': [('\\200', u
'å'),
82 'fr': [('\\200', u
'é'),
88 'it': [('\\200', u
'à'),
91 'pl': [('\\200', u
'ą'),
110 'pt': [('\\200', u
'Á'),
135 'se': [('\\200', u
'å'),
146 'all': [('\\306', u
'Δ'),
152 # Take care of command line options
153 parser
= argparse
.ArgumentParser(description
='Encoder for open9x translations')
154 parser
.add_argument('input', action
="store", help="Input file name")
155 parser
.add_argument('output', action
="store", help="Output file name")
156 parser
.add_argument('language', action
="store", help="Two letter language identifier")
157 parser
.add_argument("--reverse", help="Reversed char conversion (from number to char)", action
="store_true")
158 args
= parser
.parse_args()
160 if args
.language
not in translations
:
161 parser
.error(args
.language
+ ' is not a supported language. Try one of the supported ones: ' + str(list(translations
.keys())))
165 for translation
in translations
:
166 translations
[translation
] = [(after
, before
) for (before
, after
) in translations
[translation
]]
168 # Read the input file into a buffer
169 in_file
= codecs
.open(args
.input, "r", "utf-8")
171 # Write the result to a temporary file
172 out_file
= codecs
.open(args
.output
, 'w', 'utf-8')
174 for line
in in_file
.readlines():
175 # Do the special chars replacements
176 for after
, before
in translations
[args
.language
] + translations
["all"]:
177 line
= line
.replace(before
, after
)
178 if line
.startswith("#define ZSTR_"):
182 if ord(c
) >= ord('A') and ord(c
) <= ord('Z'):
183 c
= "\\%03o" % (ord(c
) - ord('A') + 1)
184 elif ord(c
) >= ord('a') and ord(c
) <= ord('z'):
185 c
= "\\%03o" % (-ord(c
) + ord('a') + 255)
186 elif ord(c
) >= ord('0') and ord(c
) <= ord('9'):
187 c
= "\\%03o" % (ord(c
) - ord('0') + 27)
189 line
= line
[:32] + after
+ line
[-2:]