It makes JSF support for internationalization or multiple languages easily.

Complete JSF internationalization example

In this tutorial, we show you a JSF 2.0 web application, which display a welcome page, retrieve a welcome message from properties file, and change the welcome message dynamically based on the selected language.

1. Project Folder

Directory structure for this example.

2. Properties file

Here’s two properties files to store English and Chinese message.

welcome.properties

welcome.jsf = Happy learning JSF 2.0

welcome_zh_CN.properties

welcome.jsf = \u5feb\u4e50\u5b66\u4e60 JSF 2.0

Note For UTF-8 or non-English characters, for example Chinese , you should encode it with native2ascii tool.

thanks a lottttttttt I’v been using your site always:) you saved me several times. i love u mkyong:)

tolga

i tried it with my project but the change on dropdown list does not fire the countryLocaleCodeChanged method. I clearly spoored all the things but it doesnt work. only if i change default properties file in faces-config. any idea?

I want this example to display the language of the combos in the actual language selected. Could somebody point me how this can be done?

caau dung ngok

Hi, i cannot change locale on jsf implement is myface2 when i change select item the alway is Happy learning JSF 2.0.but is show the FacesContext.getCurrentInstance().getViewRoot().getLocale() was change. please help me.

http://ghamary.ir mohammad hosein

thanks a lot I Love You…

Juan Felipe Narvaez

Hi,

I like so much this post, i have a question, how can i for that the internationalization keep in each page, because i have an error for this, when i press the indicate button that changes the language in that page but when i pass throught other page it back to the default. How can i do for that this keep the language always?

Thanks for the example, but if i refresh the page, the locale is set again to the default language.

my bean is session scoped in faces-config.

whats the matter with it.

AA

I have also facing the same problem, Have you find clue? please share if you got it. thanks

AA

I got the solution. In jsf tag which has local attribute you can set all pages language through this tag. first set the country code and assign the value to local attribute. tag should be top of the page.

alex

What he meant: In the you can set a locale (not local) attribute. Something like

&lt;f:view locale=&quot;language.locale&quot;&gt;

after the . You obviuosly need to implement a getLocale() method in the LanguageBean for that.