Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Hindi locale support?

Tags:

java

I am using Java6 for my web application i am trying below code to change the laguage of my application

public static void doChangeLanguage(String argLang) {
        SessionValidationInitiator.setLanguage(argLang);
        LOGGER.debug("Changing Language to ... " + argLang);
        if(argLang.equalsIgnoreCase("fr_ca")){
        Locales.setThreadLocal(Locales.getLocale(Locale.FRENCH));
        Executions.getCurrent().getSession().setAttribute(Attributes.PREFERRED_LOCALE, Locale.FRENCH);
        Labels.reset();
        }else{
            Locales.setThreadLocal(Locales.getLocale(Locale.US));
            Executions.getCurrent().getSession().setAttribute(Attributes.PREFERRED_LOCALE, Locale.US);
            Labels.reset();
        }
        Executions.sendRedirect(null);
    }

Its working fine but when i am trying to change the Hindi i saw no any locale for indian language.

Can we support Hindi Locale as well from Java so that my application work for Hindi Language.

like image 457
subodh joshi Avatar asked Jan 28 '14 08:01

subodh joshi


2 Answers

Java 6 definitely has Hindi Locale support, refer to here.

To explicitly set the locale to Hindi, India do something like this:

System.out.println(new Locale("hi", "IN"));

Prints;

hi_IN

The thing to note here is Locale does also offer constructors to accurately get a handle on the supported Locale(s) and variants.

Hence, in your code you might probably want to try out:

 Locales.setThreadLocal(Locales.getLocale(new Locale("hi", "IN")));
like image 185
StoopidDonut Avatar answered Oct 04 '22 11:10

StoopidDonut


In Java 6 you need this: Locale lc = new Locale("hi", "IN");

like image 31
peter.petrov Avatar answered Oct 04 '22 10:10

peter.petrov