window.translate() to translate the page to any supported language without requiring the user to interact with the widget UI. This is useful when you want to trigger translation from your own code — for example, from a custom language picker, a URL change handler, or on page load.
Signature
Parameters
BCP 47 language code of the target language. Examples:
"hi" (Hindi), "fr" (French), "es" (Spanish), "zh" (Chinese).Callback called when the translation finishes successfully. Receives a
TranslationResult object with details about the completed translation.Callback called if the translation fails. Receives an
Error object describing what went wrong.Return value
Returns aPromise<TranslationResult>. You can either await the promise or use the onComplete/onError callbacks — both are supported.
Whether the translation completed successfully.
The language code that was translated to.
Number of DOM nodes that were translated on the page.
Error message if the translation failed. Only present when
success is false.Time taken to complete the translation, in milliseconds.
Examples
Make sure the widget is initialized before calling
window.translate(). If the widget has not been initialized, the call will fail with "Translation widget not initialized".If a translation is already in progress, the call will fail immediately with
"Translation already in progress". Wait for the current translation to complete before calling window.translate() again.