Home > DeveloperSection > Forums > How to determine the language of keyboard input using Jquery
Goti Bandu

Total Post:119

Points:835
Posted on    September-02-2014 12:25 AM

 JQuery
Ratings:


 1 Reply(s)
 2274  View(s)
Rate this:

I have an application that accepts input in two languages (English and Arabic) I'm validating the input textbox , the validation logic is not the same for English and Arabic, so I need to know what is the language the user is typing

all the solutions I came across determined the default language for the system and browser but nothing I found helped me determining the current input language



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-02-2014 12:44 AM

Hi Goti, 

You can do this using Google's AJAX Language API

var content = "your text";

google.language.detect(content, function(result) {

  if (!result.error) {

    var language = 'unknown';

    for (lang in google.language.Languages) {

      if (google.language.Languages[lang] == result.language) {

        language = lang;

        break;

      }

    }

    // Now use the variable `language`

  }

});


Don't want to miss updates? Please click the below button!

Follow MindStick