How to create Google Translate API Usage in C# | MVC 5 | Free

Sometimes I have to translate lots of words to another language for localization labels, so one by one I copy and paste it on google translater and put in code. now I create API and build logic so that I can put directly labels where I want.

Use the below code.

    public async Task<ActionResult> Index()
    {
        string input = "Hello how are you";
        string strSource_Language = "en";
        string str_It = await TranslateText(strSource_Language, "hi", input);
        string str_Fr = await TranslateText(strSource_Language, "fr", input);
        return View();
    }

    public async Task<string> TranslateText(string languageSource, string languageTo, string input)
    { 
        string url = String.Format("https://translate.googleapis.com/translate_a/single?client=gtx&sl={0}&tl={1}&dt=t&q={2}", languageSource, languageTo, Uri.EscapeUriString(input));

        HttpClient httpClient = new HttpClient();
        string result = await httpClient.GetStringAsync(url);
         
        var jsonData = new JavaScriptSerializer().Deserialize<List<dynamic>>(result);
         
        var translationItems = jsonData[0];
         
        string translation = "";
         
        foreach (object item in translationItems)
        { 
            IEnumerable translationLineObject = item as IEnumerable;
             
            IEnumerator translationLineString = translationLineObject.GetEnumerator();
             
            translationLineString.MoveNext();
             
            translation += string.Format(" {0}", Convert.ToString(translationLineString.Current));
        }
         
        if (translation.Length > 1) { translation = translation.Substring(1); };
         
        return translation;
    }