translate_xliff script now accept -e option
import os
import argparse
import sys
+
sys.path.insert(0, os.path.abspath(os.path.join(__file__, os.pardir, os.pardir)))
from cli.libs import shell
from cli import IllegalArgumentException
+
def main():
# Set unbuffered stdout
unbuffered = os.fdopen(sys.stdout.fileno(), 'w', 0)
@@ -14,16 +16,18 @@ def main():
parser = argparse.ArgumentParser(description="Translate the passed file, or all the files in the passed folder")
parser.prog = 'translate_xliff.sh'
- parser.add_argument('input', metavar='INPUT', help='the xliff file or the folder containing the xliff files to translate')
+ parser.add_argument('input', metavar='INPUT',
+ help='the xliff file or the folder containing the xliff files to translate')
parser.add_argument('--context', metavar='CONTEXT', dest='context', default=None,
help='A string to be used as translation context')
parser.add_argument('--context-file', metavar='CONTEXT_FILE', dest='context_file', default=None,
help='A local file to be used as translation context')
parser.add_argument('--context-vector', metavar='CONTEXT_VECTOR', dest='context_vector', default=None,
help='The context vector with format: <document 1>:<score 1>[,<document N>:<score N>]')
+ parser.add_argument('-e', '--engine', dest='engine', help='the engine name, \'default\' will be used if absent',
+ default=None)
-
- args = parser.parse_args(sys.argv[1:])
+ args = parser.parse_args()
if os.path.isfile(os.path.abspath(args.input)):
input_file = os.path.abspath(args.input)
@@ -32,7 +36,7 @@ def main():
raise IllegalArgumentException('Input file must be either .xliff or .sdlxliff')
output_file = "/".join(input_file.split('/')[:-1]) + "/" + "out_" + input_file.split('/')[-1]
- translate_xliff_file(input_file, output_file, args.context, args.context_file, args.context_vector)
+ translate_xliff_file(input_file, output_file, args.context, args.context_file, args.context_vector, args.engine)
elif os.path.isdir(os.path.abspath(args.input)):
input_folder = os.path.abspath(args.input)
@@ -52,17 +56,20 @@ def main():
output_file_abspath = os.path.join(output_folder, "out_" + input_file)
translate_xliff_file(input_file_abspath, output_file_abspath,
- args.context, args.context_file, args.context_vector)
+ args.context, args.context_file, args.context_vector, args.engine)
else:
raise IllegalArgumentException('Input file/folder does not exist')
return
-def translate_xliff_file(input_file_abspath, output_file_abspath, context=None, context_file=None, context_vector=None):
+def translate_xliff_file(input_file_abspath, output_file_abspath,
+ context=None, context_file=None, context_vector=None, engine=None):
mmt_script = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'mmt'))
command = [mmt_script, 'translate', '--batch', '--xliff']
+ if engine:
+ command.extend(['-e', engine])
if context:
command.extend(['--context', '"' + str(context) + '"'])
if context_file:
@@ -76,6 +83,6 @@ def translate_xliff_file(input_file_abspath, output_file_abspath, context=None,
shell.execute(" ".join(command))
print "Done."
+
if __name__ == '__main__':
main()
-
