From 968f197ee4865998195091b5335c23630ea035d9 Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Fri, 15 Dec 2017 20:13:19 +0200 Subject: [PATCH] Improve calculation of the translator's approximate time Calculate the approximate time for the translator based on a new formula [(items_count * (wait_time + avg_msg)) - wait_time] instead of using only the number of entries in the PO file. --- devscripts/check-translation.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/devscripts/check-translation.py b/devscripts/check-translation.py index 754caef..c0d7107 100644 --- a/devscripts/check-translation.py +++ b/devscripts/check-translation.py @@ -197,9 +197,6 @@ def main(args): # Init translator only if the '--no-translate' flag is NOT set translator = None if not args.no_translate: - eta = timedelta(seconds=len(pot_file) * WTIME) - pinfo("Approximate time to check translations online: {}".format(eta)) - translator = google_translate.GoogleTranslator(timeout=5.0, retries=2, wait_time=WTIME) # Set source language for GoogleTranslator @@ -230,7 +227,16 @@ def main(args): else: further_analysis.append(entry) - if translator is not None: + if translator is not None and further_analysis: + # eta = (items_to_analyze * (WTIME + avg_ms)) - WTIME + # We subtract WTIME at the end because there is no wait for the last item on the list + # avg_msg = 200ms + eta_seconds = (len(further_analysis) * (WTIME + 0.2)) - WTIME + eta_seconds = int(round(eta_seconds)) + + eta = timedelta(seconds=eta_seconds) + pinfo("Approximate time to check translations online: {}".format(eta)) + # Pass translations as a list since GoogleTranslator can handle them words_dict = translator.get_info_dict([entry.msgstr for entry in further_analysis], "en", src_lang)