Translation¶
ForkBit includes a built-in translation service (DeepL or Apple Translate).
Plugins access it via translate() — translations
run asynchronously in a background thread.
Translate release notes¶
def _translate_notes(self, target_lang: str) -> None:
text = self.editor.toPlainText()
if not text.strip():
self.notify("Nothing to translate.", level="warning")
return
self.translate(
text=text,
source_lang="en",
target_lang=target_lang,
on_done=self._on_translation_done,
on_error=self._on_translation_error,
)
self.notify(f"Translating to {target_lang}...")
def _on_translation_done(self, translated_text: str) -> None:
self.editor.setPlainText(translated_text)
self.notify("Translation complete.", level="success")
def _on_translation_error(self, error: str) -> None:
self.notify(f"Translation failed: {error}", level="error")
How it works¶
translate()queues the request and returns a request ID immediatelyThe translation runs in a background thread
When finished, your
on_donecallback receives the translated textOn failure,
on_errorreceives an error message
Both callbacks run on the main thread — safe to update UI directly.
Language codes¶
Use standard language codes:
"en"— English"de"— German"fr"— French"es"— Spanish"ja"— Japanese"zh"— Chinese
The full list depends on the configured translation provider (DeepL or Apple Translate).
Next: Building & Distributing.