Skip to content

Commit

Permalink
[libretranslate] Add option for configurable timeout and docs (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hafnernuss authored Aug 22, 2024
1 parent 9741735 commit 8849e1a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/how-to/integrations/machine-translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<Your LibreTranslate api key here>",
"TIMEOUT": 40 # optional timeout in seconds, defaults to 10
},
}
```
Expand Down
5 changes: 4 additions & 1 deletion wagtail_localize/machine_translators/libretranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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()

Expand Down

0 comments on commit 8849e1a

Please sign in to comment.