Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine what the alphabet for a locale is in java?

I would like to determine what the alphabet for a given locale is, preferably based on the browser Accept-Language header values. Anyone know how to do this, using a library if necessary ?

like image 273
krosenvold Avatar asked Jan 06 '09 17:01

krosenvold


2 Answers

take a look at [LocaleData.getExemplarSet][1]

for example for english this returns abcdefghijklmnopqrstuvwxyz

[1]: http://icu-project.org/apiref/icu4j/com/ibm/icu/util/LocaleData.html#getExemplarSet(com.ibm.icu.util.ULocale, int)

like image 104
Robert Muir Avatar answered Sep 20 '22 03:09

Robert Muir


If you just want to know the name of an appropriate character set for a users locale then you might try the nio.CharSet class.

If you really want to use the Accept-Language header, then there's an old O'Reilly article on this matter which introduces a pretty handy class called LanguageNegotiator.

I think one of those will give you a decent enough start.

like image 36
GaryF Avatar answered Sep 21 '22 03:09

GaryF