Hi,

I never tried changing the locale on runtime but to make a guess;

- Get the supported locales by;

getFacesContext().getApplication().getSupportedLocales(); // This returns a locale collection;

Find the locale that the user wanted from the locale collection; And the code will look like;

String bundleName = getFacesContext().getApplication().getMessageBundle();
Locale locale = //Iterate over getSupportedLocales and find the user wanted, set it as the locale.
ResourceBundle bundle = ResourceBundle.getBundle (bundleName, locale);
String msg = bundle.getString("your key here");

P.S. This is just a guess, but I think it will likely to work. You should declare the supported locales in the faces-config as well.

Regards

Cagatay Civici,


On 1/13/06, Legolas Woodland <[EMAIL PROTECTED]> wrote:
Cagatay Civici wrote:
Hi Legolas,

You should try this;

String bundleName = getFacesContext().getApplication().getMessageBundle();
Locale locale = facesContext.getApplication().getDefaultLocale();
ResourceBundle bundle = ResourceBundle.getBundle (bundleName, locale);
String msg = bundle.getString("your key here");

regards,

Cagatay Civici


Thank you very much.
it works  , what will happen if user change the locale by using the button that i provide ?
will it return current locale ?
Thank you





On 1/12/06, Legolas Woodland < [EMAIL PROTECTED] > wrote:

Hi
Thank you for reading my message.
I have a problem , I need to load some of my resource string from String
bundle
By string bundle i mean the .properties file that we use to make
application i18n-ed .
Now i need to load some of my key from bundle file in one of my jsf page
backing bean.

for example :
in jsf i write :
<.... text="#{bundle.user_name}" />

now i want to access those keys from my java source files.
i need to access the bundle in right locale when i try to use it.

for example if locale is French i should load the key from
bundle_fr.properties .
I defined this bundle file both in my jsf page using
<f:loadBundle basename="mypackage.Bundle" var="bundle" />
and i use it in all jsf tags by that bundle variable.

now i need same access in java backing beans.

can some one  help me ?

Thank you




Reply via email to