Added a command line argument to reverse the translation. Detranslate is made obsolete by this, so it is removed.

This commit is contained in:
kjell.kernen@gmail.com
2013-06-19 07:56:51 +00:00
parent f6d1986b5c
commit 0f3928743c
2 changed files with 9 additions and 113 deletions
-108
View File
@@ -1,108 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Imports
import argparse
import os
import os.path
translations = {'cz': [('\\200', 'á'),
('\\201', 'č'),
('\\201', 'Č'),
('\\202', 'é'),
('\\203', 'ě'),
('\\204', 'í'),
('\\205', 'ó'),
('\\206', 'ř'),
('\\207', 'š'),
('\\207', 'Š'),
('\\210', 'ú'),
('\\211', 'ů'),
('\\212', 'ý'),
('\\213', 'Á'),
('\\214', 'Í'),
('\\215', 'Ř'),
('\\216', 'Ý'),
('\\217', 'ž'),
('\\217', 'Ž'),
('\\220', 'É')],
'de': [('\\200', 'Ä'),
('\\201', 'ä'),
('\\202', 'Ö'),
('\\203', 'ö'),
('\\204', 'Ü'),
('\\205', 'ü'),
('\\206', 'ß')],
'es': [('\\200', 'Ñ'),
('\\201', 'ñ')],
'fr': [('\\200', 'é'),
('\\201', 'è'),
('\\202', 'à'),
('\\203', 'î'),
('\\204', 'ç')],
'it': [('\\200', 'à'),
('\\201', 'ù')],
'pt': [('\\200', 'Á'),
('\\201', 'á'),
('\\202', 'Â'),
('\\203', 'â'),
('\\204', 'Ã'),
('\\205', 'ã'),
('\\206', 'À'),
('\\207', 'à'),
('\\210', 'Ç'),
('\\211', 'ç'),
('\\212', 'É'),
('\\213', 'é'),
('\\214', 'Ê'),
('\\215', 'ê'),
('\\216', 'Í'),
('\\217', 'í'),
('\\218', 'Ó'),
('\\219', 'ó'),
('\\220', 'Ô'),
('\\221', 'ô'),
('\\222', 'Õ'),
('\\223', 'õ'),
('\\224', 'Ú'),
('\\225', 'ú'),],
'se': [('\\200', 'å'),
('\\201', 'ä'),
('\\202', 'ö'),
('\\203', 'Å'),
('\\204', 'Ä'),
('\\205', 'Ö')],
}
# Take care of command line options
parser = argparse.ArgumentParser(description='Decoder for open9x translations')
parser.add_argument('input', action="store")
parser.add_argument('output', action="store")
parser.add_argument('language', action="store")
args = parser.parse_args()
if args.language not in translations:
parser.error(args.language + ' is not a supported language. Try one of the supported ones: ' + str(translations.keys()))
system.exit()
# Read the input file into a buffer
in_file = open( args.input, 'r')
text = in_file.read()
in_file.close()
# Do the replacements
for before, after in translations[args.language]:
text = text.replace(before, after)
# Write the result to a temporary file
out_file = open( args.output, 'w')
out_file.write( text )
out_file.close()
+9 -5
View File
@@ -82,9 +82,10 @@ translations = {'cz': [('\\200', 'á'),
# Take care of command line options
parser = argparse.ArgumentParser(description='Encoder for open9x translations')
parser.add_argument('input', action="store")
parser.add_argument('output', action="store")
parser.add_argument('language', action="store")
parser.add_argument('input', action="store", help="Input file name")
parser.add_argument('output', action="store", help="Output file name")
parser.add_argument('language', action="store", help="Two letter language identifier")
parser.add_argument("--reverse", help="Reversed char conversion (from number to char)", action="store_true")
args = parser.parse_args()
if args.language not in translations:
@@ -98,8 +99,11 @@ in_file.close()
# Do the replacements
for before, after in translations[args.language]:
text = text.replace(after, before)
if args.reverse:
text = text.replace(before, after)
else:
text = text.replace(after, before)
# Write the result to a temporary file
out_file = open( args.output, 'w')
out_file.write( text )