Translate Method

Translate Method

This method launches the Widget which translates the current page to the desired language. A callback function provides you translation progress information.


Microsoft.Translator.Widget.Translate(from, to, onProgress:(value), onError: (error), onComplete:(), onRestoreOriginal:(toLanguage), timeOut);


Parameter Description
from Optional. A string representing the language code of the original text. If set to null, the source language is autodetected from the page.
to Required. A string representing the language code to translate the text into.
onProgress Optional. A function delegate that receives an integer value from 0-100 indicating how much of the page is translated.
onError Optional. A function delegate that receives a string that describes an error upon occurrence.
onComplete Optional. A function delegate that is called when the page translation is complete, similar to calling onProgress(100)
timeOut Optional. A number in milliseconds to abort the function after if the translation is not complete, consider using large values with larger pages.



Dn341982.alert_note(en-us,MSDN.10).gif Note

You may exclude specific site content from translation by the widget through the use of the custom attribute translate=no or class=notranslate. Any element with either of these attributes set will be excluded from the widgets translation and will therefore remain in its original language. This feature is also demonstrated in the example code.


<!DOCTYPE html>
<html xmlns="">
    <title>Microsoft Widget API Sample</title>
    <script src="**" type="text/javascript"></script>
    <script type="text/javascript">
        document.onreadystatechange = function () {
            if (document.readyState == 'complete') {
                Microsoft.Translator.Widget.Translate('en', 'es', onProgress, onError, onComplete, onRestoreOriginal, 2000);
        //You can use Microsoft.Translator.Widget.GetLanguagesForTranslate to map the language code with the language name
        function onProgress(value) {
            document.getElementById('counter').innerHTML = Math.round(value);

        function onError(error) {
            alert("Translation Error: " + error);

        function onComplete() {
            document.getElementById('counter').style.color = 'green';
        //fires when the user clicks on the exit box of the floating widget
        function onRestoreOriginal() { 
            alert("The page was reverted to the original language. This message is not part of the widget.");


<!-- The attribute: translate="no" tells the widget not to translate this block of text -->
    <div style="text-align: right" translate="no">
        <span>Translation Progress </span><span id="counter" style="color: red">0</span><span>%</span>
            The page will display an error message box if the widget takes more than two seconds to finish
    <div style="text-align: center" >
        The widget will translate this text. The widget will translate this text. The widget will translate this text. 


© 2015 Microsoft