[jsr-314-open] localePrefix

Cay Horstmann cay at horstmann.com
Sun Oct 25 00:23:38 EDT 2009


Kito Mann wrote:
 > That's great to hear Martin. Cay Hortsman and David Geary agree as well.
 >

I sent Kito the current status of the section in Core JavaServer Faces 
regarding this sordid issue. I would be very happy to rewrite it if a 
more appealing implementation were to materialize. IMNSHO, what you need 
to do here is (1) implement fallback and (2) lose that localePrefix, 
except for backward compatibility, in case anyone made use of it.

Also consider the fact that the only entry in faces-config.xml in a good 
number of the Core JavaServer Faces examples is the resource bundle. A 
dose of convention over configuration would eliminate that. For example, 
you may want to automatically pick up /resources/bundle.properties and 
make it accessible in an EL variable "bundle". With proper locale 
support and fallback, or course.

Cheers,

Cay

<quote>

There is also a mechanism for supplying localized versions of resources. 
Unfortunately, that mechanism is unintuitive and not very useful. 
Localized resources have a prefix, such as resources/de_DE/images, but 
the prefix is not treated in the same way as a bundle suffix. There is 
no fallback mechanism. That is, if an image is not found in 
resources/de_DE/images, then resources/de/images and resources/images 
are not consulted.

Moreover, the locale prefix is not simply the current locale. Instead, 
it is obtained by a curious lookup, which you enable by following these 
steps:

Add the line

<message-bundle>name of a resource bundle used in your 
application</message-bundle>

inside the application element of faces-config.xml

Inside each localized version of that resource bundle, place a 
name/value pair

javax.faces.resource.localePrefix=prefix

Place the matching resources into resources/prefix/library/...

For example, if you use the message bundle com.corejsf.messages, and the 
file com.corejsf.messages_de contains the entry

javax.faces.resource.localePrefix=german

then you place the German resources into resources/german. (The prefix 
need not use the standard language and country codes, and in fact it is 
a good idea not to use them so that you don’t raise false hopes.)

CAUTION: Unfortunately, this localization scheme is unappealing in 
practice. Once you define a locale prefix, that prefix is used for all 
resources. Suppose you wanted to have different images for the German 
and English versions of your site. Then you would also have to duplicate 
every other resource. Hopefully, this will be fixed in a future version 
of JSF.

</quote>

-- 

Cay S. Horstmann | http://horstmann.com | mailto:cay at horstmann.com




More information about the jsr-314-open-mirror mailing list