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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]