GetLanguagesForTranslate Method

Returns a list of Language objects with localized names according to the locale parameter provided.

Syntax


Microsoft.Translator.Widget.GetLanguagesForTranslate(locale, onComplete(languages),onError:(error), timeOut);
						

Parameters

Parameter Type Description
locale string Required. Language code of the localization language. Must be a valid culture name.
onComplete function Required. A function delegate that is fired upon completion, receiving ILanguage[] of all the supported languages for translation.
onError function Optional. A function delegate that receives a string that describes an error upon occurrence.
timeOut number Optional. A number in milliseconds to abort the function after if the value is not returned.

Returns

void. The language list is returned in the OnComplete function as an array of ILanguage object instances. The ILanguage object contains the following propoerties:

Property Type Description
Code string Culture name for the language.
Name string Friendly name for the language - in the locale specified.

Example



<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Microsoft Widget API Sample</title>
    <script src="http://microsofttranslator.com/ajax/v3/widgetv3.ashx" type="text/javascript"></script>
    <script type="text/javascript">
        document.onreadystatechange = function () {
            if (document.readyState == 'complete') {
                Microsoft.Translator.Widget.GetLanguagesForTranslate('en',
                    function (supportedLanguages) {
                        //the input parameter of the callback is an array of a custom object that holds two properties, Name and Code
                        fillList(supportedLanguages, 'langs');
                    },
                    function (error) {
                        alert(error);
                    }
                );
                //Filling the second select with the list of languages localized in Arabic
                Microsoft.Translator.Widget.GetLanguagesForTranslate('ar',
                    function (supportedLanguages) {
                        fillList(supportedLanguages, 'langsArabic');
                    },
                    function (error) {
                        alert(error);
                    }
                );

                //Filling a table with the list of languages localized in Japanese
                Microsoft.Translator.Widget.GetLanguagesForTranslate('ja',
                    function (supportedLanguages) {
                        fillTable(supportedLanguages);
                    },
                    function (error) {
                        alert(error);
                    }
                );
            }
        }
        function fillList(listOfLanguages, listId) {
            var ddlLangs = document.getElementById(listId);
            for (var key in listOfLanguages) {
                var optLang = document.createElement('option');
                //Language name is in .Name property
                optLang.innerHTML = listOfLanguages[key].Name;
                //Langauge code is .Code property
                optLang.value = listOfLanguages[key].Code;
                ddlLangs.appendChild(optLang);
            }
        }

        function fillTable(listOfLanguages) {
            var tbl = document.getElementById('tbleLangs').children[0];

            for (var key in listOfLanguages) {
                var row = document.createElement('tr');
                var c1 = document.createElement('td');
                c1.innerHTML = listOfLanguages[key].Code;
                var c2 = document.createElement('td');
                c2.innerHTML = listOfLanguages[key].Name;
                row.appendChild(c1);
                row.appendChild(c2);
                tbl.appendChild(row);
            }
        }
    </script>
    <style type="text/css">
        div
        {
            margin: 7px;
        }
        table, th, td
        {
            border: 1px solid;
            border-collapse: collapse;
            min-width: 100px;
            padding: 3px;
        }
    </style>
</head>
<body>
    <div>
        <span>List of supported languages: </span>
        <select id="langs">
        </select>
    </div>
    <div>
        <span>List of supported languages in Arabic: </span>
        <select id="langsArabic" style="direction: rtl">
        </select>
    </div>
    <div>
        <span>Table of languages' codes and names localized in Japanese</span>
        <table id="tbleLangs">
            <tbody>
                <tr>
                    <th>
                        Code
                    </th>
                    <th>
                        Name
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</body>
</html>

						


Show: