You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by N G <ni...@gmail.com> on 2005/07/12 22:14:50 UTC

Parameterized messages

Hi,

Is it possible to use the resource properties for keys as well as
args? For example,

<bean:message key="test.val1" arg0="test.val2"/>

Properties:
test.val1=hello {0}
test.val2=world

So, what I am trying to accomplish is to have the above statement output:
hello world

However, it outputs:
hello test.val2

Is there a way to force it to look up the properties again?

Thanks,
NG

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Parameterized messages

Posted by Martin Gainty <mg...@hotmail.com>.
I am unsure why you want to translate the key instead of translating the 
associated value..
But if your encoding scheme of the source files, destination files and the 
bundle files are specified
I would suggest looking at ant's <translate> task at
http://ant.apache.org/manual/OptionalTasks/translate.html

Anyone else?
Martin-

----- Original Message ----- 
From: "N G" <ni...@gmail.com>
To: "Struts-user" <us...@struts.apache.org>
Sent: Tuesday, July 12, 2005 4:14 PM
Subject: Parameterized messages


Hi,

Is it possible to use the resource properties for keys as well as
args? For example,

<bean:message key="test.val1" arg0="test.val2"/>

Properties:
test.val1=hello {0}
test.val2=world

So, what I am trying to accomplish is to have the above statement output:
hello world

However, it outputs:
hello test.val2

Is there a way to force it to look up the properties again?

Thanks,
NG

---------------------------------------------------------------------
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


Re: Parameterized messages

Posted by Laurie Harper <la...@holoweb.net>.
Rick Reumann wrote:
> N G wrote the following on 7/12/2005 4:14 PM:
>> Is it possible to use the resource properties for keys as well as
>> args? For example,
>>
>> <bean:message key="test.val1" arg0="test.val2"/>
>>
>> Properties:
>> test.val1=hello {0}
>> test.val2=world
>>
>> So, what I am trying to accomplish is to have the above statement output:
>> hello world
>>
>> However, it outputs:
>> hello test.val2
> 
> Not sure if you could nest bean:message, I'm guessing no, but I know a 
> way around it using JSTL. (fmt:message acts the same as bean:message it 
> will pull from your ApplicationResources)...
> 
> <fmt:message key='test.val2' var='fooBar'/>
> <fmt:message key='test.val1'>
>    <fmt:param value='${fooBar}'/>
> </fmt:message>
> 
> If you decide to use JSTL fmt:message just remember to put something 
> like this in your web.xml:
> 
> <context-param>
>     <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
>     <param-value>ApplicationResources</param-value>
>   </context-param>
> 
> (assumes ApplicationResources is your properties file found in root of 
> classes.... at least the above works for me.. might be a better way)

It's worth bearing in mind that doing this sort of thing can make 
localization difficult since sentance structure varies from language to 
language. Whilst that would be easy to work around in this simple example 
(by changing both test.val1 and test.val2 in the resources), it can be a 
lot less straighy forward if the text you're inserting (text.val2) isn't 
just a single word. Particularly in languages where the value of text.val2 
would be dependent on the context in which it was used...

Parameter substitution is best reserved for simple value insertion rather 
than building up composite phrases if you want to remain flexible for 
localization.

L.
-- 
Laurie, Open Source advocate, Java geek and novice blogger:
http://www.holoweb.net/~laurie/


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Parameterized messages

Posted by Rick Reumann <st...@reumann.net>.
N G wrote the following on 7/12/2005 4:14 PM:
> Hi,
> 
> Is it possible to use the resource properties for keys as well as
> args? For example,
> 
> <bean:message key="test.val1" arg0="test.val2"/>
> 
> Properties:
> test.val1=hello {0}
> test.val2=world
> 
> So, what I am trying to accomplish is to have the above statement output:
> hello world
> 
> However, it outputs:
> hello test.val2

Not sure if you could nest bean:message, I'm guessing no, but I know a 
way around it using JSTL. (fmt:message acts the same as bean:message it 
will pull from your ApplicationResources)...


<fmt:message key='test.val2' var='fooBar'/>
<fmt:message key='test.val1'>
    <fmt:param value='${fooBar}'/>
</fmt:message>


If you decide to use JSTL fmt:message just remember to put something 
like this in your web.xml:

<context-param>
     <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
     <param-value>ApplicationResources</param-value>
   </context-param>

(assumes ApplicationResources is your properties file found in root of 
classes.... at least the above works for me.. might be a better way)


-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org