How to check string is English or German or any other language other than English using java

I have to prepare a property file where key is English and value can be other than English, like German, Chinese, Korean, French. I read key and value from xml file. I used one linkedhashmap, as sequence also matters, now if:

  1. first encounters key and value both are English, I inserted in map, next time if key is same but value can be in German, then I to replace English word with German.
  2. if first time I found English key with German value, i hv to do nothing.

I tried to get bytcodes with UTF-8 but it works for korean or chines but not in German.

byte[] bytes = value.replace(" ", "").getBytes("UTF-8");

or

if(value.charAt(i)>=128){
    ret = false;
}

I need a method which accept string as input, if string is English return true, rest for all language it should return false.

boolean isEng(String abc){
if(abc is english)
return true;
}
else
return false
}

abc = "Change Password" should return true, abc = "Changer le mot de passe" should return false

Jon Skeet
people
quotationmark

I would strongly advise you to have separate property files, one for each language. Heck, that's the scenario that PropertyResourceBundle is made for.

Fundamentally you can't tell what language a word is - there are many words which are valid in multiple languages, sometimes with the same meanings and sometimes with different meanings. (Think "formidable" in English and French for example...) Heck, a single word in one language can have multiple meanings...

Imagine you have keys K1 and K2, and values A and B, with the following mappings:

English K1 = A
German K1 = B

English K2 = B
German K1 = A

That may sound far fetched, and I'm not about to look for an example of it, but it's far from impossible.

Any time you want your code to make a decision based on whether it thinks a particular word is in one language or another, you're in a world of pain. For a larger piece of text, with enough work, you can determine this heuristically - but even so it'll never be perfect. For single words, it'll be a lot worse than "not perfect".

people

See more on this question at Stackoverflow