diff --git a/docs/how-to/integrations/machine-translation.md b/docs/how-to/integrations/machine-translation.md index 9673ddbd..653bba0d 100644 --- a/docs/how-to/integrations/machine-translation.md +++ b/docs/how-to/integrations/machine-translation.md @@ -146,6 +146,7 @@ WAGTAILLOCALIZE_MACHINE_TRANSLATOR = { "LIBRETRANSLATE_URL": "https://libretranslate.org", # or your self-hosted instance URL # For self-hosted instances without API key setup, use a random string as the API key. "API_KEY": "", + "TIMEOUT": 40 # optional timeout in seconds, defaults to 10 }, } ``` diff --git a/wagtail_localize/machine_translators/libretranslate.py b/wagtail_localize/machine_translators/libretranslate.py index b897fb53..32a6a74f 100644 --- a/wagtail_localize/machine_translators/libretranslate.py +++ b/wagtail_localize/machine_translators/libretranslate.py @@ -19,6 +19,9 @@ class LibreTranslator(BaseMachineTranslator): def get_api_endpoint(self): return self.options["LIBRETRANSLATE_URL"] + def get_timeout(self): + return self.options.get("TIMEOUT", 10) + def language_code(self, code): return code.split("-")[0] @@ -36,7 +39,7 @@ def translate(self, source_locale, target_locale, strings): } ), headers={"Content-Type": "application/json"}, - timeout=10, + timeout=self.get_timeout(), ) response.raise_for_status()