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:
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
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".
See more on this question at Stackoverflow