1

I have a JSF2 application and so far I'm doing the internationalization in a typical way with a message resource bundle; example:

<f:view contentType="text/html" locale="#{loginHandler.currentLocale}">

<f:loadBundle basename="MessageResource" var="msg" />

<h:outputText value="#{msg.user_firstNameLabel}" />

My problem is I have an information page with paragraphs of content in two languages. I prefer not to take every line of text on the page and make them key|values in the message properties file.

If the content is in two html files; say contactus_en.html and contactus_fr.html, what would be the right way to display the right language based on the current locale?

Thanks! Rob

1 Answers1

2

The easiest way to do what you are asking for is to create a controller that would read the contents of your HTML files and return them on demand. In such case you can write out it from your JSF page with very simple declaration:

<h:outputText escape="false" value="#{yourController.contactus}" />

Since you are going to read the contents of HTML file(s), you need to tell JSF not to escape them (thus escape="false").
Of course your controller need to provide method named getContactus() which should read the contents of HTML files of your interest and return them as String. I believe you can easily handle it :)


Edit - adding information about how to choose file.

If your HTML files are locale-dependent so these are already bi-lingual but different for English and French, you can easily get current view Locale from UIViewRoot:

Locale currentLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
String fileName = "contactus_" + currentLocale.toString() + ".html";
Paweł Dyda
  • 18,366
  • 7
  • 57
  • 79