You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Colin Kilburn <co...@accesstec.ca> on 2004/10/20 23:14:50 UTC
i18n of bean properties/data
Hi All,
I'm not sure if this has been done before as I can't see any reference
in the archives, but I have a hard time believing I'm the only one.
I have to support multiple languages in my app. I can successfully set
my users' locales using the Action.setLocale() method as well as the
jstl equivalent of Config.setAttribute(...). I have an
ApplicationResources file for each language I need to support (English
and French), and this covers all my form captions and success/error
messages. This was slick and easy. Great.
Now, most of my forms (and I know I'm not alone here) have select lists
to choose an item such as country, favorite color, or whatever. These
fields usually correspond to foreign keys in my database, so I load the
appropriate lists from the database. Often this data must be bilingual
too, so in these select boxes, I need to display a different column's
data in the list depending on the user's locale.
For example:
Say I have a bean called Color with three properties: id, name, nameFr
-- corresponding to the default (English) and French versions of the
select option. Depending on the locale, I want to display the
appropriate property (labelProperty) in the options list. What I'd
like to be able to do is say:
<html:options collection="colorList" property="id" labelProperty="name"/>
and have the tag know that based on the locale, if it were french, that
it should use nameFr as the labelProperty (if such a property exists).
I can imagine how I could implement a subclass of the <html:options/>
tag to do this (with a big help from BeanUtils), but I'm wondering if
anyone else has tackled this type of thing before. I can also forsee
needing an equivalent alternative to a <c:out/> or perhaps
<bean:write/>, that knows to append the locale to the property name of
the bean specified.
I hope this makes sense. I'm ready to roll my own here, but I wanted
to see if anyone else has been here before. Any comments/ideas
appreciated.
Colin
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: i18n of bean properties/data
Posted by Hubert Rabago <hr...@gmail.com>.
If it were up to me, I'd use a collection of LabelValueBean objects
with the label containing the values I want to show accd to the user's
Locale. I think it would be much easier than writing a custom tag.
On Wed, 20 Oct 2004 18:14:50 -0300, Colin Kilburn <co...@accesstec.ca> wrote:
> Hi All,
>
> Say I have a bean called Color with three properties: id, name, nameFr
> -- corresponding to the default (English) and French versions of the
> select option. Depending on the locale, I want to display the
> appropriate property (labelProperty) in the options list. What I'd
> like to be able to do is say:
>
> <html:options collection="colorList" property="id" labelProperty="name"/>
>
> and have the tag know that based on the locale, if it were french, that
> it should use nameFr as the labelProperty (if such a property exists).
>
> I can imagine how I could implement a subclass of the <html:options/>
> tag to do this (with a big help from BeanUtils), but I'm wondering if
> anyone else has tackled this type of thing before. I can also forsee
> needing an equivalent alternative to a <c:out/> or perhaps
> <bean:write/>, that knows to append the locale to the property name of
> the bean specified.
>
> I hope this makes sense. I'm ready to roll my own here, but I wanted
> to see if anyone else has been here before. Any comments/ideas
> appreciated.
>
> Colin
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org