You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by hezjing <he...@gmail.com> on 2008/02/11 16:13:12 UTC

[S2] Subsitute variable in i18n properties file

Hi

If I have a message defined in i18n properties file shown below,

    label.welcome = Welcome ${name}

How can I subsitute the variable "name" in the JSP?
I tried the following and obviously it doesn't work!

    <s:label key="label.welcome">
    <s:param name="name">John</s:param>
    </s:label>


May be it is a good idea to describe the solution in
http://struts.apache.org/2.x/docs/localization.html?


-- 

Hez

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


Re: [S2] Subsitute variable in i18n properties file

Posted by hezjing <he...@gmail.com>.
>> <label><s:text name="label.welcome"><s:param>John</s:param></s:text></label>
This one works!

> label.welcome = Welcome {name}
>
> <s:label key="label.welcome">
> <s:param name="name">John</s:param>
> </s:label>
>
This one doesn't work, it displayed a colon ":" instead of the message
from the i18n properties file.

> label.welcome = Welcome {0}
>
> <s:label key="label.welcome">
> <s:param>John</s:param>
> </s:label>
>
This will throw the following exception,
java.lang.NullPointerException
        at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:121)
        at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:100)
        at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:73)
        at org.apache.struts2.components.Component.findValue(Component.java:313)
        at org.apache.struts2.components.Component.findString(Component.java:194)
        ...

On Feb 12, 2008 7:21 AM, Wes Wannemacher <we...@wantii.com> wrote:
> IIRC, you can use named parameters. If you want to keep the {name}, use
>
> label.welcome = Welcome {name}
>
> <s:label key="label.welcome">
> <s:param name="name">John</s:param>
> </s:label>
>
>
>
>
> On Mon, 2008-02-11 at 09:10 -0800, Chris Pratt wrote:
> > Change your property to
> >
> > label.welcome = Welcome {0}
> >
> > Then you might try:
> >
> > <s:label key="label.welcome">
> >   <s:param>John</s:param>
> > </s:label>
> >
> > If that doesn't work, you should be able to use:
> >
> > <label><s:text name="label.welcome"><s:param>John</s:param></s:text></label>
> >
> >   (*Chris*)
> >
> > On Feb 11, 2008 7:13 AM, hezjing <he...@gmail.com> wrote:
> > > Hi
> > >
> > > If I have a message defined in i18n properties file shown below,
> > >
> > >     label.welcome = Welcome ${name}
> > >
> > > How can I subsitute the variable "name" in the JSP?
> > > I tried the following and obviously it doesn't work!
> > >
> > >     <s:label key="label.welcome">
> > >     <s:param name="name">John</s:param>
> > >     </s:label>
> > >
> > >
> > > May be it is a good idea to describe the solution in
> > > http://struts.apache.org/2.x/docs/localization.html?
> > >
> > >
> > > --
> > >
> > > Hez
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 

Hez

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


Re: [S2] Subsitute variable in i18n properties file

Posted by Wes Wannemacher <we...@wantii.com>.
IIRC, you can use named parameters. If you want to keep the {name}, use 

label.welcome = Welcome {name}

<s:label key="label.welcome">
<s:param name="name">John</s:param>
</s:label>



On Mon, 2008-02-11 at 09:10 -0800, Chris Pratt wrote:
> Change your property to
> 
> label.welcome = Welcome {0}
> 
> Then you might try:
> 
> <s:label key="label.welcome">
>   <s:param>John</s:param>
> </s:label>
> 
> If that doesn't work, you should be able to use:
> 
> <label><s:text name="label.welcome"><s:param>John</s:param></s:text></label>
> 
>   (*Chris*)
> 
> On Feb 11, 2008 7:13 AM, hezjing <he...@gmail.com> wrote:
> > Hi
> >
> > If I have a message defined in i18n properties file shown below,
> >
> >     label.welcome = Welcome ${name}
> >
> > How can I subsitute the variable "name" in the JSP?
> > I tried the following and obviously it doesn't work!
> >
> >     <s:label key="label.welcome">
> >     <s:param name="name">John</s:param>
> >     </s:label>
> >
> >
> > May be it is a good idea to describe the solution in
> > http://struts.apache.org/2.x/docs/localization.html?
> >
> >
> > --
> >
> > Hez
> >
> > ---------------------------------------------------------------------
> > 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
> 


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


Re: [S2] Subsitute variable in i18n properties file

Posted by Chris Pratt <th...@gmail.com>.
Change your property to

label.welcome = Welcome {0}

Then you might try:

<s:label key="label.welcome">
  <s:param>John</s:param>
</s:label>

If that doesn't work, you should be able to use:

<label><s:text name="label.welcome"><s:param>John</s:param></s:text></label>

  (*Chris*)

On Feb 11, 2008 7:13 AM, hezjing <he...@gmail.com> wrote:
> Hi
>
> If I have a message defined in i18n properties file shown below,
>
>     label.welcome = Welcome ${name}
>
> How can I subsitute the variable "name" in the JSP?
> I tried the following and obviously it doesn't work!
>
>     <s:label key="label.welcome">
>     <s:param name="name">John</s:param>
>     </s:label>
>
>
> May be it is a good idea to describe the solution in
> http://struts.apache.org/2.x/docs/localization.html?
>
>
> --
>
> Hez
>
> ---------------------------------------------------------------------
> 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