Facilitates text translation between different language pairs using on-device or browser-integrated AI models. It includes built-in methods to verify if specific language pairs (e.g., English to Spanish) are supported before attempting the translation.
| Name | Type | Description |
|---|---|---|
| options.sourceLanguage | string | The BCP 47 code for the source language. Required. |
| options.targetLanguage | string | The BCP 47 code for the target language. Required. |
| options.onLanguageSupportCheck | (supported: boolean) => void | Callback triggered after checking if the language pair is usable. Default: undefined. |
| Name | Type | Description |
|---|---|---|
| checkLanguageSupport | () => Promise<boolean> | Manually triggers a check for the configured language pair. |
| error | Error | null | Captures API errors or unsupported language exceptions. |
| isLanguagePairSupported | boolean | null | Result of the support check (null if not yet checked). |
| isSupported | boolean | true if the browser supports the window.translator API. |
| isTranslating | boolean | true while the AI model is processing the translation. |
| translate | (text: string) => Promise<string> | Triggers the translation process for the provided text. |
| translation | string | null | The most recent translation result. |