tags:

views:

51

answers:

2

We have a requirement to show a certain page alone in a different locale. (e.g in a certain page if the topic of discussion is related to English then we pick up the messages from the messages_en.properties, but if the topic of discussion is in French or German we need to show the messages in the appropriate language.

How to change the following bean invocation to take in the locale as a parameter in the xhtml page #{messages['label.hello']}.

The above defaults to the english locale, how do I pass the locale dynamically?

+3  A: 

On the server side, just do it

private @In LocaleSelector localeSelector;

And set up as follows

localeSelector.setLanguage("en");
localeSelector.setCountry("US");
Arthur Ronald F D Garcia
Will check to see if this makes a difference prior to rendering that page
Joshua
@Joshua ok. Let me know later!
Arthur Ronald F D Garcia
+2  A: 

I want to note that JSF also reads the preferred language in your browser, and displays that if that language is supported by your application.

So really if you support lots of languages, then you don't need to define server side locale.

In faces-config.xml

 <application>
  <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
  <locale-config>
     <default-locale>en</default-locale>
     <supported-locale>se</supported-locale>
     <supported-locale>dk</supported-locale>
     <supported-locale>no</supported-locale>
     <supported-locale>it</supported-locale>
     <!-- etc -->
  </locale-config>

Shervin
@Shervin - The page I am talking about will be using the english properties file most of the time. But based on a certain topic, it needs to be shown in a different locale. Note: this is not end user locale driven, but is driven based on the topic of discussion). So its not clear to me on how to make the messages bean take the locale
Joshua