0

After entering data in EditText,how do we know the data which is in English or Chinese or other language.Thanks in advance.

Note : EditText should allow multiple language. We don't restrict the user to enter data in default language

3 Answers3

1

for that you dont need to wait for user to enter the text..

Locale.getDefault().getDisplayLanguage();

will return the device's current set language.

Also

You can use Locale.getDefault().getLanguage(); to get the usual language code (e.g. "de", "en").

Kalpesh Lakhani
  • 1,003
  • 14
  • 28
  • 3
    Yes but you can set your device in English and write in French. I don't think this is what the OP is looking for. – user2336315 Jan 18 '14 at 13:04
  • EditText should allow multiple language. We don't restrict the user to enter data in default language –  Jan 18 '14 at 13:04
0

Auto-detecting the natural language of a text is relatively easy using a bigram analysis algorithm. You can either implement it by yourself or simply use some existing library, e.g. Language-Detection project. Auto detection

learner
  • 3,092
  • 2
  • 21
  • 33
0

i found this helpful:

LangDetector detector = new LangDetector();
detector.register("fr", frenchTree);
detector.register("en", englishTree);

gives result like this:

JLangDetect, with the previous corpus, does really well with both short and long texts. However, it will do better with longer texts (if anyone can tell me in which language is written the word "chocolate"...).

Here's a simple output of JLangDetect. OK means language has been detected properly. Error means not.

langof("un texte en français") = fr : OK
langof("a text in english") = en : OK
langof("un texto en español") = es : OK
langof("un texte un peu plus long en français") = fr : OK
langof("a text a little longer in english") = en : OK
langof("a little longer text in english") = en : OK
langof("un texto un poco mas longo en español") = es : OK
langof("J'aime les bisounours !") = fr : OK
langof("Bienvenue à Montmartre !") = fr : OK
langof("Welcome to London !") = en : OK
langof("un piccolo testo in italiano") = it : OK
langof("een kleine Nederlandse tekst") = nl : OK
langof("Matching sur des lexiques") = fr : OK
langof("Matching on lexicons") = en : OK
langof("Une première optimisation consiste à ne tester que les sous-chaînes de taille compatibles avec le lexique.") = fr : OK
langof("A otimização é a primeira prova de que não sub-canais compatível com o tamanho do léxico.") = pt : OK
langof("Ensimmäinen optimointi ei pidä testata, että osa-kanavien kanssa koko sanakirja.") = fi : OK
langof("chocolate") = es : Error
langof("some chocolate") = it : Error
langof("eating some chocolate") = en : OK

complete reference is here.

Hamad
  • 5,096
  • 13
  • 37
  • 65