2 # -*- coding: utf-8 -*-
9 translations
= {'cz_reduced': [('\\200', u
'á'),
31 'cz': [('\\200', u
'ě'),
62 'de': [('\\200', u
'Ä'),
70 'es': [('\\200', u
'Ñ'),
73 'fi': [('\\200', u
'å'),
80 'fr': [('\\200', u
'é'),
86 'it': [('\\200', u
'à'),
89 'pl': [('\\200', u
'ą'),
108 'pt': [('\\200', u
'Á'),
133 'se': [('\\200', u
'å'),
144 'all': [('\\306', u
'Δ'),
150 # Take care of command line options
151 parser
= argparse
.ArgumentParser(description
='Encoder for open9x translations')
152 parser
.add_argument('input', action
="store", help="Input file name")
153 parser
.add_argument('output', action
="store", help="Output file name")
154 parser
.add_argument('language', action
="store", help="Two letter language identifier")
155 parser
.add_argument("--reverse", help="Reversed char conversion (from number to char)", action
="store_true")
156 args
= parser
.parse_args()
158 if args
.language
not in translations
:
159 parser
.error(args
.language
+ ' is not a supported language. Try one of the supported ones: ' + str(list(translations
.keys())))
163 for translation
in translations
:
164 translations
[translation
] = [(after
, before
) for (before
, after
) in translations
[translation
]]
166 # Read the input file into a buffer
167 in_file
= codecs
.open(args
.input, "r", "utf-8")
169 # Write the result to a temporary file
170 out_file
= codecs
.open(args
.output
, 'w', 'utf-8')
172 for line
in in_file
.readlines():
173 # Do the special chars replacements
174 for after
, before
in translations
[args
.language
] + translations
["all"]:
175 line
= line
.replace(before
, after
)
176 if line
.startswith("#define ZSTR_"):
180 if ord(c
) >= ord('A') and ord(c
) <= ord('Z'):
181 c
= "\\%03o" % (ord(c
) - ord('A') + 1)
182 elif ord(c
) >= ord('a') and ord(c
) <= ord('z'):
183 c
= "\\%03o" % (-ord(c
) + ord('a') + 255)
184 elif ord(c
) >= ord('0') and ord(c
) <= ord('9'):
185 c
= "\\%03o" % (ord(c
) - ord('0') + 27)
187 line
= line
[:32] + after
+ line
[-2:]