Is there any way to know whether a String is English or not? My situation is here: I want to basically show Helvetica font in popup menu, but change the font when a menu item has other language in order to prevent garbage characters. Ideally I want to create a menu item that multi fonts are mixed (ex. If English, it’s drawn with Helvetica. If Japanese, another font is selected). Thank you,[/quote]
It’s easy, make a Markov chain (for each language you want to detect) using a good list of english words, another with spanish words, etc.
Then, to detect the language of a string, process the string with these matrices and sum the values of transition that are activated with each character of the string. The “string*matrix” that outputs the highest transitions sumatory will tell you the most probable language of the string.
But if you only need to detect between english and japanese, you can get a UTF-32 copy of the string and check if there are chars in the ranges of the Unicode Kanji tables (0x3000-0x30FF and 0x4E00-0x9FAF), if that’s the case then the string is in japanese.