From 801a5117d8c78884fc85a430c71a1bbd68a497d5 Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Fri, 15 Dec 2017 14:57:02 +0200 Subject: [PATCH] Dont initiate translator if the '--no-translate' flag is set --- devscripts/check-translation.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/devscripts/check-translation.py b/devscripts/check-translation.py index aa4a0da..2488d4c 100644 --- a/devscripts/check-translation.py +++ b/devscripts/check-translation.py @@ -198,22 +198,25 @@ def main(args): if msgid not in po_msgid: missing_msgid.append(msgid) - translator = google_translate.GoogleTranslator(timeout=5.0, retries=2, wait_time=WTIME) + # Init translator only if the '--no-translate' flag is NOT set + translator = None + if not args.no_translate: + translator = google_translate.GoogleTranslator(timeout=5.0, retries=2, wait_time=WTIME) - # Set source language for GoogleTranslator - if args.tlang is not None: - src_lang = args.tlang - pinfo("Forcing '{}' as the translator's source language".format(src_lang)) - else: - # Get a valid source language for Google - # for example convert 'ar_SA' to 'ar' or 'zh_CN' to 'zh-CN' - src_lang = args.language - - if src_lang not in translator._lang_dict: - src_lang = src_lang.replace("_", "-") + # Set source language for GoogleTranslator + if args.tlang is not None: + src_lang = args.tlang + pinfo("Forcing '{}' as the translator's source language".format(src_lang)) + else: + # Get a valid source language for Google + # for example convert 'ar_SA' to 'ar' or 'zh_CN' to 'zh-CN' + src_lang = args.language if src_lang not in translator._lang_dict: - src_lang = src_lang.split("-")[0] + src_lang = src_lang.replace("_", "-") + + if src_lang not in translator._lang_dict: + src_lang = src_lang.split("-")[0] for entry in po_file: if not entry.translated(): @@ -223,7 +226,7 @@ def main(args): same_msgstr.append(entry) else: - if args.no_translate: + if translator is None: continue word_dict = translator.get_info_dict(entry.msgstr, "en", src_lang)