简体   繁体   中英

How do I display the message in a different locale

We have a requirement to show a certain page alone in a different locale. (eg 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?

On the server side, just do it

private @In LocaleSelector localeSelector;

And set up as follows

localeSelector.setLanguage("en");
localeSelector.setCountry("US");

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM