The right way to do internationalization in JSF for full HTML pages?

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

<f:view contentType="text/html" locale="#{loginHandler.currentLocale}"> <f:loadBundle basename="MessageResource" var="msg" /> <h:outputText value="#{msg.user_firstNameLabel}" /> 

My problem is that 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 correct language based on the current locale?

Thanks! Rob

+1
source share
1 answer

The easiest way to do what you ask is to create a controller that will read the contents of your HTML files and return them on demand. In this case, you can write it from your JSF page with a very simple declaration:

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

Since you're going to read the contents of HTML files, you need to tell JSF so that they don't escape them (thus escape = "false").
Of course, your controller needs to provide a method called getContactus() , which should read the contents of your HTML files and return them as String. I believe you can easily handle this :)


Edit - Add information on how to select a file.

If your HTML files are language-dependent, so they are already bilingual, but different for English and French, you can easily get the current Locale view from UIViewRoot:

 Locale currentLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); String fileName = "contactus_" + currentLocale.toString() + ".html"; 
+3
source

All Articles