Re: Best Practices for PrettyFaces and Multiple language sites

Splash Forums PrettyFaces Users Best Practices for PrettyFaces and Multiple language sites Re: Best Practices for PrettyFaces and Multiple language sites

#20693

Hey Ignacio,

I think it is not a very good idea to implement i18n by using different xhtml files. You should really use the standard JSF way for i18n.

What about doing something like this. Define a parent mapping containing the language as a path parameter that is injected into a request scoped bean:

<url-mapping id="parent">
<pattern value="/#{localeBean.language}" />
...
</url-mapping>

The bean:

@Named
@RequestScoped
public class LocaleBean {

private String language;

public String getLanguage() {
return language;
}

public String setLanguage(String language) {
this.language = language;
}

public getLocale() {
return new Locale(language);
}

}

Then use the getLocale() method of the bean and use it to set the locale of your view:

<f:view locale=#{localeBean.locale}>

<!-- your page -->

</f:view>

This way the view will have the correct locale set and you will be able to use the standard JSF 118n techniques for loading localized messages from a MessageBundle.

I didn’t test this in details but thats how I would try it! :-)