jqueryasp.netgoogle-translategoogle-translator-toolkit

Translate TextBox Text using Google Translate API in ASP.Net


I am using the following code to translate English to German

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="https://www.google.com/jsapi">
    </script>
    <script type="text/javascript">
        // Load the Google Transliterate API
        google.load("elements", "1", {
            packages: "transliteration"
        });

        function onLoad() {
            var options = {
                sourceLanguage:
                google.elements.transliteration.LanguageCode.ENGLISH,
                destinationLanguage:
                [google.elements.transliteration.LanguageCode.HINDI],
                shortcutKey: 'ctrl+e',
                transliterationEnabled: true
            };

            // Create an instance on TransliterationControl with the required
            // options.
            var control =
            new google.elements.transliteration.TransliterationControl(options);

            // Enable transliteration in the textbox with id
            // 'transliterateTextarea'.
            control.makeTransliteratable(['transliterateTextarea']);


        }
        google.setOnLoadCallback(onLoad);
    </script>
</head>
<body>
    <span>English to German</span><br>
    <form runat="server">
    <div>
        <asp:TextBox ID="transliterateTextarea" runat="server" TextMode="MultiLine" Rows="5"
            Columns="50" />
    </div>
    </form>
</body>
</html>

For English to Hindi its working fine. but it's not working for English to German.I want convert text English to German help is much appreciated. Thanks in advance


Solution

  • The code you are using to convert is English to German language but unfortunately google.elements.transliteration.LanguageCode./(German) is not supported in the Transliterate API.

    All includes all languages supported in the Transliterate API.

    var google.elements.transliteration.SupportedDestinationLanguages = {       
        // As support for more languages becomes available, this enum will be
        // automatically updated to include the new languages transparently.
        ALL: [
            google.elements.transliteration.LanguageCode.AMHARIC,
            google.elements.transliteration.LanguageCode.ARABIC,
            google.elements.transliteration.LanguageCode.BENGALI,
            google.elements.transliteration.LanguageCode.CHINESE,
            google.elements.transliteration.LanguageCode.GREEK,
            google.elements.transliteration.LanguageCode.GUJARATI,
            google.elements.transliteration.LanguageCode.HINDI,
            google.elements.transliteration.LanguageCode.KANNADA,
            google.elements.transliteration.LanguageCode.MALAYALAM,
            google.elements.transliteration.LanguageCode.MARATHI,
            google.elements.transliteration.LanguageCode.NEPALI,
            google.elements.transliteration.LanguageCode.ORIYA,
            google.elements.transliteration.LanguageCode.PERSIAN,
            google.elements.transliteration.LanguageCode.PUNJABI,
            google.elements.transliteration.LanguageCode.RUSSIAN,
            google.elements.transliteration.LanguageCode.SANSKRIT,
            google.elements.transliteration.LanguageCode.SERBIAN,
            google.elements.transliteration.LanguageCode.SINHALESE,
            google.elements.transliteration.LanguageCode.TAMIL,
            google.elements.transliteration.LanguageCode.TELUGU,
            google.elements.transliteration.LanguageCode.TIGRINYA,
            google.elements.transliteration.LanguageCode.URDU],
    
        // INDIC includes all Indic languages supported in the Transliterate API.
        // As support for more Indic languages becomes available, this enum will be
        // automatically updated to include the new languages transparently.
        INDIC: [
            google.elements.transliteration.LanguageCode.BENGALI,
            google.elements.transliteration.LanguageCode.GUJARATI,
            google.elements.transliteration.LanguageCode.HINDI,
            google.elements.transliteration.LanguageCode.KANNADA,
            google.elements.transliteration.LanguageCode.MALAYALAM,
            google.elements.transliteration.LanguageCode.MARATHI,
            google.elements.transliteration.LanguageCode.NEPALI,
            google.elements.transliteration.LanguageCode.ORIYA,
            google.elements.transliteration.LanguageCode.PUNJABI,
            google.elements.transliteration.LanguageCode.SANSKRIT,
            google.elements.transliteration.LanguageCode.SINHALESE,
            google.elements.transliteration.LanguageCode.TAMIL,
            google.elements.transliteration.LanguageCode.TELUGU,
            google.elements.transliteration.LanguageCode.URDU]
    };