Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option for configurable timeout and docs #802

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -35,7 +38,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