Forums Register Login

how to set Context Input Method to specific locale (without country code)

+Pie Number of slices to send: Send
Hi,
i'm using selectInputMethod(new Locale("ar", "AE")) to set the locale for my application. this works fine but the problem is that i should specify the country code as well e.g. "AE", without this it will not work e.g. new Locale("ar")
Arabic language is the same for all countries so the country is not a matter here. i don't know which country code language is installed in the user PC. i want the application to select any Arabic language installed in the user PC.
Locale.getAvailableLocales() is not giving me what i need. it gives all the supported languages in the OS but not the ones that are enabled by the user.
i ended up duplicating selectInputMethod for all the country codes i.e.:

this.getInputContext().selectInputMethod(new Locale("ar", "DZ"));
this.getInputContext().selectInputMethod(new Locale("ar", "IQ"));
this.getInputContext().selectInputMethod(new Locale("ar", "JO"));
this.getInputContext().selectInputMethod(new Locale("ar", "LB"));
this.getInputContext().selectInputMethod(new Locale("ar", "LY"));
this.getInputContext().selectInputMethod(new Locale("ar", "MA"));
this.getInputContext().selectInputMethod(new Locale("ar", "OM"));
this.getInputContext().selectInputMethod(new Locale("ar", "SD"));
this.getInputContext().selectInputMethod(new Locale("ar", "SY"));
this.getInputContext().selectInputMethod(new Locale("ar", "TN"));
this.getInputContext().selectInputMethod(new Locale("ar", "YE"));
this.getInputContext().selectInputMethod(new Locale("ar", "QA"));
this.getInputContext().selectInputMethod(new Locale("ar", "KW"));
this.getInputContext().selectInputMethod(new Locale("ar", "BH"));
this.getInputContext().selectInputMethod(new Locale("ar", "EG"));
this.getInputContext().selectInputMethod(new Locale("ar", "SA"));
this.getInputContext().selectInputMethod(new Locale("ar", "AE"));

this will pick certainly one Arabic language in the user PC.

Is there any other better way?
+Pie Number of slices to send: Send
 

Reyada Wolak wrote:the problem is that i should specify the country code as well e.g. "AE", without this it will not work e.g. new Locale("ar")


What exactly do you mean when saying 'it will not work'? -> ItDoesntWorkIsUseless

Personally I never encountered problems using Locales without specifying the country code. Did you ever analyze the return value of method selectInputMethod()? Are you aware of it's function/implementation as stated in the docs?
-> http://java.sun.com/javase/6/docs/api/java/awt/im/InputContext.html#selectInputMethod(java.util.Locale)
+Pie Number of slices to send: Send
it means that the input language didn't change from en_US (default locale) to ar_X
i.e. i need to specify the country code or it will not work.

the selectInputMethod() return false in case of Locale("ar"), the same as Locale("en")

there is no bug in the implementation but i need to know how do i get the enabled input language (not the list of the supported languages since i cannot select them unless the user add them from the control panel)
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3268 times.
Similar Threads
Bilingual JSP application
trouble in setDefaultLocale
Strange behavior of the JVM related to Arabization(Localization)
The method print(boolean) in the type JspWriter is not applicable for the arguments(void)
Internationalization (i18n)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:05:48.