From 43453aadd374e8aa14d4e5f74faff4bf64ef8c9d Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Fri, 22 Nov 2024 16:26:59 -0800 Subject: [PATCH] translations: Add script to autotranslate. --- share/qtcreator/translations/translate.py | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 share/qtcreator/translations/translate.py diff --git a/share/qtcreator/translations/translate.py b/share/qtcreator/translations/translate.py new file mode 100644 index 00000000000..9231b0e6d46 --- /dev/null +++ b/share/qtcreator/translations/translate.py @@ -0,0 +1,53 @@ +#!/usr/bin/python + +# Copyright (C) 2023-2024 OpenMV, LLC. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Any redistribution, use, or modification in source or binary form +# is done solely for personal benefit and not for any commercial +# purpose or for monetary gain. For commercial licensing options, +# please contact openmv@openmv.io +# +# THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT +# OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import subprocess +from concurrent.futures import ThreadPoolExecutor +import argparse + +def translate_file(file_name): + language_code = file_name.split('_')[1].split('.')[0] + command = f"python -u CuteLingoExpress/auto_trans.py {file_name} en {language_code}" + process = subprocess.Popen(command, shell=True) + process.wait() + +def main(): + parser = argparse.ArgumentParser(description="Translate files in parallel.") + parser.add_argument('--max-connections', type=int, default=5, help='Maximum number of active connections (default: 5)') + args = parser.parse_args() + + ts_files = [f for f in os.listdir('.') if f.startswith('qtcreator_') and f.endswith('.ts')] + with ThreadPoolExecutor(max_workers=args.max_connections) as executor: + executor.map(translate_file, ts_files) + +if __name__ == "__main__": + main()