• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multilingual JSF

 
Mujtaba Alsaif
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default answer to having a multilingual page when developing an application is to develop two pages. This will usually add the complexity of managing the pages by resulting in the added effort of maintaining both pages/forms when having adding/amending a function. A simple solution to the problem is by considering the language to be as a separate function and manage it accordingly.

In-line with the function of multi-lingual, let us use the terminology of Function-Oriented application (as a sub-level of OO) where the function of presentation is isolated from the function of language and, as such, is isolated from the core function of the application. Within JSF, you can easily isolate the functionality of a multi lingual application. Let us start by a bundle two bundle files (This can be in a database if you prefer). Here I will use Arabic and English

BundleEn.bundle


BundleAr.bundle


Then Create a Managed Bean with the scope set as Session Scoped (This is to ensure you maintain the selected language)



Finally, your JSF page. Depending on the label you need to retrieve, you may use the expression language in the following form:


where dir while define the orientation of the page (left to right or right to left), next and previous will refer to the label title next and Previous respectively in the bundle bundle file based on the selected language. By implementing you code in the above manner, you open the opportunity to configure new languages as you feel free and it will require minimum maintenance from a technical perspective.

 
Tim Holloway
Bartender
Posts: 18418
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your contribution Mujtaba.

However, the construct:

is bad practice. You should almost never code function calls in your View Definition, whether it's mono-lingual or multi-lingual. Even worse is if you put parameters in such calls. JSF works primarily on server-side data.


Code an action method reference, instead.


Likewise for properties:

Should be

Where the "label" property is a Map object. Or, when using multiple languages, a façade for whichever Bundle map is presently used for the selected language.
 
Mujtaba Alsaif
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim

I was unaware. However, I was attempting to provide a generic template to develop multi lingual apps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!