How To Convert English Word (Source Language) To Other Language (Target Language) Using Google Translate API

Introduction

In this article, we will learn how to convert English words (Source Language) to other language (Target Language) using Google Translate API.

Let’s begin

Google Translate API

     https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=ur&dt=t&q={keys}

sl – Source Language Code Like en, hi, ur etc.

tl –  Target Language Code Like en, hi, ur etc.

{keys} – your word

Different Language Code

Hindi – hi

Gujarati – gu

English – en

Marathi – mr

More Languages Code Here.

Google Translate API Using POSTMAN

Google Translate API Using Jquery

Below code add in your jquery file and get word to your target language.

function SourceLanguageToTargetLanguage() {
     var sourceLanguage = "en";
     var targetLanguage = "hi";
     var word="Your Word";
     var googleTranslateURL = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" + sourceLanguage + "&tl=" + targetLanguage + "&dt=t&q=" + word;
            var requestOptions = {
                method: 'GET',
                redirect: 'follow'
            };
            fetch(googleTranslateURL)
                .then(res => res.json())
                .then(res => {
                    if (res && res[0] && res[0][0] && res[0][0][0]) {
                        name = res[0][0][0];
                    }
       });
}

Output :

If you have any questions or issues about this article, please let me know.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories