HOW TO DETERMINE THE LANGUAGE OF KEYBOARD INPUT USING JQUERY

Goti Bandu

Total Post:119

Points:835
Posted by  Goti Bandu
 3110  View(s)
Ratings:
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

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: How to determine the language of keyboard input using Jquery

    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`

      }

    });

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!