aspose file tools*
The moose likes JSF and the fly likes Internationalization in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Internationalization in JSF" Watch "Internationalization in JSF" New topic
Author

Internationalization in JSF

Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
Hi All

Please could someone give me some advice on internationalization best practice for JSF. I know what I am trying to achieve but not the best method. I would appreciate any guidance.

Requirements
============
I want a ResourceBundle accessible to my JSF pages, backing beans and model objects loaded from a properties file.
I dont want to load the ResourceBundle for every page or object use, I would like it stored in session scope.
The localised resource bundle has to be of the type LC_CC_VC where LC=language, CC=country and VC=variant.
I would like to be able to access messages in JSF pages using expression language.

Can anyone advise how I can achieve the above?

Where should I set the Locale in the UIViewRoot?
Do I need to set the supported locales in the XML config file?
Should I ignore the JSF features and just create my own ResourceBundle and stick it in Session scope?
How can I access messages from a resource bundle without having a specific getter?

What would you do?

Thanks for your advice in advance - there are too many options for me to pick the best way to do this.

So far I have tried this route
==============================
Extract locale from DB after login
Create ResourceBundle in login method of backing bean
Store Resourcebundle in session scope

This is OK but it means I cannot use EL to access my messages so I am looking for another solution.

Cheers


ph34r my 133t j4v4 h4><0r1ng sk177z
Chris Gage
Greenhorn

Joined: Mar 23, 2005
Posts: 17

JSF should do it all for you provided you tell it which languages you want to enable in the faces-config.xml file.

Fort example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link rel="stylesheet" type="text/css" href="../theme/Master.css" />
<title>Yada Yada Yada</title>
</head>
<f:view>
<f:loadBundle var="MyMain" basename="MyMain" />
<body>
<h utputText value="#{MyMain.my_message_key}" />
</body>
</f:view>
</html>

and in your faces-config.xml, something like:

<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>fr</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>es</supported-locale>
<supported-locale>nl</supported-locale>
...
</locale-config>
</application>
Chris Gage
Greenhorn

Joined: Mar 23, 2005
Posts: 17

Please ignore the silly face which the website inserted without asking me. It replaced a colon followed by a letter o with this silly symbol.
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
If a view is not associated with a locale explicity, JSF uses "Accept-Language" header in request data from browser to find out the locale to be picked. It compares the header's values with the ones configured in faces-config.xml and if no match is found default locale is selected.


- Varun
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Originally posted by Chris Gage:
Please ignore the silly face which the website inserted without asking me. It replaced a colon followed by a letter o with this silly symbol.


Alternatively, while replying you may check Disable smilies in this post. option at the bottom of the screen
Ronald Johnson
Greenhorn

Joined: Jan 15, 2007
Posts: 18
i am coding a "switch language" into an app,
and my idea is that i have a bean that stores the language setting.
as default, the Accept-language should be used,
i.e. in the bean, i would either returned the user defined lanuage or the value of Accept-language.

how can i read out the value of Accept-language from my java code?
Y Jadhav
Ranch Hand

Joined: Oct 02, 2008
Posts: 37
Chris Gage wrote:Please ignore the silly face which the website inserted without asking me. It replaced a colon followed by a letter o with this silly symbol.


CHECK "Disable Smilies ...." option while sending reply...
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Kind of you, but in the future please don't resurrect old and dead topics. Just leave them for what they are and respond to active topics in the listing only.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Internationalization in JSF