Getting Locale Code

Hi,

I am trying to apply jQuery Validation plugin into dhis2 india branch.

For showing the error messages in different languages, I need a language code. But could not find this code anywhere. So what I did is adding this method into “I18n” class:

public String getCurrentLocaleCode()
{
    if( specificResourceBundle != null )
    {
        return specificResourceBundle.getLocale().getLanguage() + "_" + specificResourceBundle.getLocale().getCountry();

    }
    if( globalResourceBundle != null )
    {
        return globalResourceBundle.getLocale().getLanguage() + "_" + globalResourceBundle.getLocale().getCountry();
    }
    return null;

}

So … is this a good way ? If not, please suggest me a better way.

And I can also apply this plugin to global branch if you want.

Thanks,

···


Nguyen Pham Hoang Quoc Viet

Hey Viet,

have a look at the LocaleManager, you can find the interface in the api and the impl in dhis-i18n-static (UserSettingLocaleManager), bean id is org.hisp.dhis.i18n.locale.LocaleManager. It provides a method getCurrentLocale() which returns the java.util.Locale currently in use based on the user setting, and returns the default locale if no user setting exists.

Lars

···

On Tue, Jan 5, 2010 at 8:22 AM, Viet Nguyen phamquocviet@gmail.com wrote:

Hi,

I am trying to apply jQuery Validation plugin into dhis2 india branch.

For showing the error messages in different languages, I need a language code. But could not find this code anywhere. So what I did is adding this method into “I18n” class:

public String getCurrentLocaleCode()
{
    if( specificResourceBundle != null )
    {
        return specificResourceBundle.getLocale().getLanguage() + "_" + specificResourceBundle.getLocale().getCountry();



    }
    if( globalResourceBundle != null )
    {
        return globalResourceBundle.getLocale().getLanguage() + "_" + globalResourceBundle.getLocale().getCountry();
    }
    return null;



}

So … is this a good way ? If not, please suggest me a better way.

And I can also apply this plugin to global branch if you want.

Thanks,


Nguyen Pham Hoang Quoc Viet


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp