9

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.

subodh joshi
  • 365
  • 3
  • 10
  • 1
    [JDK 7 and JRE 7 Supported Locales](http://www.oracle.com/technetwork/java/javase/javase7locales-334809.html) suggests that `hi_IN` is Hindi. Given the absolute ease in which I found that info, you get a down-vote for me for lack of research. – Duncan Jones Jan 28 '14 at 08:28

2 Answers2

14

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")));
JJJ
  • 32,902
  • 20
  • 89
  • 102
StoopidDonut
  • 8,547
  • 2
  • 33
  • 51
1

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

peter.petrov
  • 38,363
  • 16
  • 94
  • 159