Detect language of latin word on mvc using google translation api

Hi, please how we can detect if a latin string is in English or French or not recognized on MVC razor c# using google translation API ??? Thank u :) ...

Asked by:- LuneAgile
: 4075 At:- 9/18/2017 10:50:06 AM
Google translation api C# razor

2 Answers
profileImage Answered by:- vikas_jk

You can do it using C# using the code below

static object DetectLanguage(string text)
    TranslationClient client = TranslationClient.Create();
    var detection = client.DetectLanguage(text);
    Console.WriteLine("{0}\tConfidence: {1}",
        detection.Language, detection.Confidence);
    return 0;

Note: To run above Code, you should install Google.TranslateApi in your project using Nuget
install-package Google.Cloud.Translation.V2 -pre

but before you run the above code, you need to authorize your credentials from google using the key of the Google OAuth project, using the code below

string credential_path = @"C:\..\key.json";
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credential_path);

Note: To get credentials or key, you must have Enabled Google Translation API in your project, created using with proper billing Methods to use this Api

You can also do it using jQuery Ajax by sending POST request on Google Translation Enabled API on this URL

With test body as

  'q': 'Google Translate Rocks',

Output would be

  "data": {
    "detections": [
          "confidence": 0.24697750806808472,
          "isReliable": false,
          "language": "en"

here are the few links which will help you in achieving above solution

1. (Using C#)

2.  (Using Ajax)

3. (Using Credentials for ASP.NET)

I could have shown you proper Code with example if the API would have been free to use, but above details should be enough for reference, let me know how if you find any issue using the above code

At:- 9/18/2017 12:41:06 PM Updated at:- 9/18/2017 12:43:08 PM

profileImage Answered by:- LuneAgile

Noted. Thank you so much Vikas_jk I will try your specs  code and inform you if I have some issues ... 

At:- 9/18/2017 4:11:55 PM Updated at:- 9/18/2017 4:13:54 PM
you can comment like above details in the comment section of an answer, as above details looks like a comment on the answer, not an answer, thanks 0
By : pika - at :- 9/19/2017 10:43:38 AM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use