You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pranav <me...@yahoo.com> on 2008/04/21 05:37:09 UTC
Intenationalization questions
Hi,
I am new to struts 2 and trying to figure out a problem that I am having w.r.t. I18n. My application is supposed to serve multiple clients per hosted instance of the application and the requirement is to somehow support the requirement of display of client specific text for the same message resource key based on the logged in user. E.g. so if an end user is logging on to the system on behalf of customer 1 the same key "welcome.user" should display message different from what another end user of customer 2 sees for the same message resource key. Note that the locale is still the same i.e. US English. I was thinking about the following solution:
Solution: I will extend ActionSupport class and all its getText method such that each key will be prefixed by something unique to the customer like customer_id before the lookup and each messageresouce file will define the same key multiple times with the customer_id as prefix as needed. E.g. cust1.welcome.user, cust2.welcome.user etc.
Now my questions are:
1) If I do the above, do I always have to use the getText way of looking up the messages? If I use the key attribute of the UI tags, will the overridden getText methods be still called?
2) Also is there any major problem with the approach above to solve the particular problem I am having?
Thanks and regards
Pranav
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Intenationalization questions
Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Pranav wrote:
> Hi,
>
>
> Now my questions are:
> 1) If I do the above, do I always have to use the getText way of looking up the messages? If I use the key attribute of the UI tags, will the overridden getText methods be still called?
>
Yes. The Struts2 tags with a key attribute and the s:text tag call the
get getText(...) methods of the first TextProvider encountered in the
stack. This is usually your action if you extended ActionSupport. Note
that if you use the i18n tag it won't work as that tag creates an
alternative TextProvider in front of your action.
> 2) Also is there any major problem with the approach above to solve the particular prolem I am having?
>
>
It seems appropriate for a small number of customers. Create a custom
TextProvider and delegate to it from your new base class, providing the
customer-specific key.
If this needs to scale out to a large number of customers, change your
TextProvider implementation to load a resource bundle for each customer
and a default resource bundle (ie. don't use customer specific keys; use
customer-specific bundles that take precedence over the default
values). Eventually you'll also be able to switch to database-backed
resource bundles to add custom customers dynamically if the need arises.
Hope that helps,
Jeromy Evans
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Intenationalization questions
Posted by Ralf Fischer <th...@googlemail.com>.
Hi,
On Mon, Apr 21, 2008 at 5:37 AM, Pranav <me...@yahoo.com> wrote:
> Hi,
>
> I am new to struts 2 and trying to figure out a problem that I am having w.r.t. I18n. My application is supposed to serve multiple clients per hosted instance of the application and the requirement is to somehow support the requirement of display of client specific text for the same message resource key based on the logged in user. E.g. so if an end user is logging on to the system on behalf of customer 1 the same key "welcome.user" should display message different from what another end user of customer 2 sees for the same message resource key. Note that the locale is still the same i.e. US English. I was thinking about the following solution:
I don't know if I get it right, but I think the solution is much more simpler.
You mentioned you want to display a different welcome message for each
user. Is this "welcome.user" really that different or is it just
something like "Hi there, dear user [username]!" ?
If so, you can do this with the default <s:text /> tag, by just adding
a <s:param /> to it:
<s:text name="welcome.user">
<s:param value="user.name" />
</s:text>
The message in the bundle then has to look like this:
welcome.user=Hi there, dear user {0}!
You can add arbitrary parameters to message texts, and even format
numbers and so on. The Text-component uses the Default
java.text.MessageFormat class to render the message including the
parameters.
Cheers,
-Ralf
> Solution: I will extend ActionSupport class and all its getText method such that each key will be prefixed by something unique to the customer like customer_id before the lookup and each messageresouce file will define the same key multiple times with the customer_id as prefix as needed. E.g. cust1.welcome.user, cust2.welcome.user etc.
>
> Now my questions are:
> 1) If I do the above, do I always have to use the getText way of looking up the messages? If I use the key attribute of the UI tags, will the overridden getText methods be still called?
> 2) Also is there any major problem with the approach above to solve the particular problem I am having?
>
> Thanks and regards
> Pranav
>
>
>
>
>
> ____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org