Detect language of latin word on asp.net mvc using google translation api


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


Asked by:- LuneAgile
0
: 4225 At:- 9/18/2017 10:50:06 AM
Google translation api asp.net-mvc 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 https://console.developers.google.com 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

https://translation.googleapis.com/language/translate/v2/detect?key=YOUR_API_KEY

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. https://cloud.google.com/translate/docs/detecting-language#translate-detect-language-csharp (Using C#)

2. https://cloud.google.com/translate/docs/reference/detect#body.QUERY_PARAMETERS  (Using Ajax)

3. https://developers.google.com/identity/protocols/application-default-credentials#callingdotnet (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

3
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 ... 

0
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
Or
Register directly by posting answer/details

Full Name *

Email *




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