You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andy Blower <an...@proquest.co.uk> on 2008/04/02 20:43:09 UTC

T5: Expansions & prefixes

I'm accessing message catalogs using expansion with a prefix. e.g.
${message:this-is-my-key}

1) Is there a list of prefixes anywhere, or have I got them all now?
(literal, prop, message)

2) Is there a way of accessing a message with a key that's partially
generated by another expansion? 
e.g. (this doesn't work obviously, but getProductVariant() is implemented in
the page class and its output forms the last segment of the message key) 
${message:product-name-${productVariant}}

3) Also how can you pass arguments to the messages to replace {0}, {1} etc?

Thanks,

Andy.
-- 
View this message in context: http://www.nabble.com/T5%3A-Expansions---prefixes-tp16448078p16448078.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Expansions & prefixes

Posted by Andy Blower <an...@proquest.co.uk>.
Thanks for all the replies everyone.

This is good, but it'd be better if the prefix could be passed in from the
template. I guess it would need another property & setter. I'm still a
novice with Tapestry, but I can't think of a way of doing this without
creating a component and having it take a parameter. It's not possible to do
${messagePrefix('product-name')}  and have it call
setMessagePrefix('product-name') or anything is it?

Thanks,

Andy.


Imants Firsts wrote:
> 
> 2) Use your property like this in the template
> ${prop:myMessage}, and in code define it as follows:
> @Inject
> private Messages _messages;
> public String getMyMessage() {
>   return _messages.get("product-name-" +
> getProductVariant());
> }
> 
> 3) _messages.format("product-name", param1, param2);
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-Expansions---prefixes-tp16448078p16467345.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Expansions & prefixes

Posted by Imants Firsts <im...@inbox.lv>.
1) See the Binding Expressions section.
http://tapestry.apache.org/tapestry5/tapestry-core/guide/parameters.html

2) Use your property like this in the template
${prop:myMessage}, and in code define it as follows:
@Inject
private Messages _messages;
public String getMyMessage() {
  return _messages.get("product-name-" +
getProductVariant());
}

3) _messages.format("product-name", param1, param2);

Best Regards,
Imants

Quoting Andy Blower <an...@proquest.co.uk>:
> I'm accessing message catalogs using expansion with a
prefix. e.g.
> ${message:this-is-my-key}
> 
> 1) Is there a list of prefixes anywhere, or have I
got them all now?
> (literal, prop, message)
> 
> 2) Is there a way of accessing a message with a key
that's partially
> generated by another expansion? 
> e.g. (this doesn't work obviously, but
getProductVariant() is implemented
> in
> the page class and its output forms the last segment
of the message key)
> 
> ${message:product-name-${productVariant}}
> 
> 3) Also how can you pass arguments to the messages to
replace {0}, {1}
> etc?
> 
> Thanks,
> 
> Andy.
> -- 
> View this message in context:
>
http://www.nabble.com/T5%3A-Expansions---prefixes-tp16448078p16448078.html
> Sent from the Tapestry - User mailing list archive at
Nabble.com.
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail:
users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Expansions & prefixes

Posted by Petros Petrou <pe...@cypoz.com>.
You may want to read this
http://tapestry.apache.org/tapestry5/tapestry-core/guide/parameters.html


Andy Blower wrote:
> 
> I'm accessing message catalogs using expansion with a prefix. e.g.
> ${message:this-is-my-key}
> 
> 1) Is there a list of prefixes anywhere, or have I got them all now?
> (literal, prop, message)
> 
> 2) Is there a way of accessing a message with a key that's partially
> generated by another expansion? 
> e.g. (this doesn't work obviously, but getProductVariant() is implemented
> in the page class and its output forms the last segment of the message
> key) 
> ${message:product-name-${productVariant}}
> 
> 3) Also how can you pass arguments to the messages to replace {0}, {1}
> etc?
> 
> Thanks,
> 
> Andy.
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-Expansions---prefixes-tp16448078p16451740.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Expansions & prefixes

Posted by Peter Beshai <pe...@gmail.com>.
1) I'm not sure if there is a list anywhere, but I know there are more
prefixes than those ;> 'var' is one!

2/3) You most likely want to do something like this:
XX.properties:
product-name = Apple Sauce - %s

Then when you want to use it, you will need to add a property to your
page/component:

@Inject
private Messages _messages;

public String getProductNameWithVariant()
{
return _messages.format("product-name", getProductVariant());
}

Then refer to it as ${productNameWithVariant} in your template.

Or, you may be interested in using a binding from the t5components package:
http://213.160.23.119:8080/t5components/t5c-commons/howto_messageformatbinding.html

On Wed, Apr 2, 2008 at 2:43 PM, Andy Blower <an...@proquest.co.uk>
wrote:

>
> I'm accessing message catalogs using expansion with a prefix. e.g.
> ${message:this-is-my-key}
>
> 1) Is there a list of prefixes anywhere, or have I got them all now?
> (literal, prop, message)
>
> 2) Is there a way of accessing a message with a key that's partially
> generated by another expansion?
> e.g. (this doesn't work obviously, but getProductVariant() is implemented
> in
> the page class and its output forms the last segment of the message key)
> ${message:product-name-${productVariant}}
>
> 3) Also how can you pass arguments to the messages to replace {0}, {1}
> etc?
>
> Thanks,
>
> Andy.
> --
> View this message in context:
> http://www.nabble.com/T5%3A-Expansions---prefixes-tp16448078p16448078.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: Expansions & prefixes

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Hi,

It's done. You can see the result at 
http://wiki.apache.org/tapestry/Tapestry5HowToAddMessageFormatBindingPrefix.

I've tested this on two of my sites and it works beautifully.

I've added support for multi-part keys so you can do stuff like 
${format:gender-,prop:user.gender} which will get you the message 
gender-male or gender-female depending on user.gender. This can, of 
course, be combined with formatting if needed.

-Filip

On 2008-04-03 01:33, Filip S. Adamsen wrote:
> I've been thinking about adding support for this to the 
> MessageFormatBindingPrefix found on this wiki page: 
> http://wiki.apache.org/tapestry/Tapestry5HowToAddMessageFormatBindingPrefix
> 
> If you take a look at it the code, MessageFormatBindingFactory in 
> particular, you'll see that making the message key itself a binding 
> wouldn't be too difficult. It should probably default to literal to 
> preserve current behaviour, though.
> 
> You can have a go at it yourself or wait a few days for me to do it.
> 
> -Filip

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Expansions & prefixes

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Hi,

On 2008-04-03 11:26, Andy Blower wrote:
> Filip - that looks really good work. 
> 
> I didn't realise new bindings can be created. I'm surprised that you're
> using %d, %s etc rather than the standard {0} {1} ResourceBundle parameters.
> To me it would be nicer expressed like this:  (can you overload bindings?)

That's because it's the format Tapestry itself uses for its message 
bundles. I'm actually using Tapestry's message binding under the covers. 
I suppose one could change this without too much hassle if needed.

And you can't override the message prefix. That's why I called mine 
'messageformat'. I'm actually using 'format' in my own applications. 
Overloading, if I understand you correctly, is just a matter of 
processing the binding expression in your binding.

> ${message:key(param0,param1,...,paramN)}
> 
> The other thing is can the params be the strings from other messages? This
> is something I've done a fair amount in JSP & JSTL to reduce duplication of
> translated text in properties files.

It sure can. The MessageFormatBindingPrefix supports that natively, like 
this (values with no prefix default to prop: unless they're 
single-quoted, in which case they're taken as literals):

   ${format:key-name=message:other-key,'1',productname}

So if you add a new binding it can be used in there as well. Again, I'm 
just building this on top of Tapestry's binding prefix support.

> I'm really not quite sure what "making the message key itself a binding"
> would mean or how it would help, sorry if it's obvious but I'm very new to
> Tapestry. I'll certainly not be doing it myself any time soon, I'm just
> evaluating the framework at the moment.

What I mean is that you could have this:

   ${format:prop:property='whatever','properties','you','need','etc'}

> Thanks,
> 
> Andy.

-Filip

> 
> Filip S. Adamsen-2 wrote:
>> I've been thinking about adding support for this to the 
>> MessageFormatBindingPrefix found on this wiki page: 
>> http://wiki.apache.org/tapestry/Tapestry5HowToAddMessageFormatBindingPrefix
>>
>> If you take a look at it the code, MessageFormatBindingFactory in 
>> particular, you'll see that making the message key itself a binding 
>> wouldn't be too difficult. It should probably default to literal to 
>> preserve current behaviour, though.
>>
>> You can have a go at it yourself or wait a few days for me to do it.
>>
>> -Filip
>>
>> On 2008-04-02 20:43, Andy Blower wrote:
>>> I'm accessing message catalogs using expansion with a prefix. e.g.
>>> ${message:this-is-my-key}
>>>
>>> 1) Is there a list of prefixes anywhere, or have I got them all now?
>>> (literal, prop, message)
>>>
>>> 2) Is there a way of accessing a message with a key that's partially
>>> generated by another expansion? 
>>> e.g. (this doesn't work obviously, but getProductVariant() is implemented
>>> in
>>> the page class and its output forms the last segment of the message key) 
>>> ${message:product-name-${productVariant}}
>>>
>>> 3) Also how can you pass arguments to the messages to replace {0}, {1}
>>> etc?
>>>
>>> Thanks,
>>>
>>> Andy.
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Expansions & prefixes

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Hi,

I just use another name entirely.

-Filip

On 2008-04-03 11:59, Andy Blower wrote:
> Understanding dawned about 5 minutes after submitting the message - always
> the way. You can't override bindings because MappedConfiguration.add()
> throws an exception if the key is not unique. Have you figured out how to do
> this from the T5 source code, or is there some documentation I've missed?
> 
> 
> Andy Blower wrote:
>> Filip - that looks really good work. 
>>
>> I didn't realise new bindings can be created. I'm surprised that you're
>> using %d, %s etc rather than the standard {0} {1} ResourceBundle
>> parameters. To me it would be nicer expressed like this:  (can you
>> overload bindings?)
>>
>> ${message:key(param0,param1,...,paramN)}
>>
>> The other thing is can the params be the strings from other messages? This
>> is something I've done a fair amount in JSP & JSTL to reduce duplication
>> of translated text in properties files.
>>
>> I'm really not quite sure what "making the message key itself a binding"
>> would mean or how it would help, sorry if it's obvious but I'm very new to
>> Tapestry. I'll certainly not be doing it myself any time soon, I'm just
>> evaluating the framework at the moment.
>>
>> Thanks,
>>
>> Andy.
>>
>>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Expansions & prefixes

Posted by Andy Blower <an...@proquest.co.uk>.
Understanding dawned about 5 minutes after submitting the message - always
the way. You can't override bindings because MappedConfiguration.add()
throws an exception if the key is not unique. Have you figured out how to do
this from the T5 source code, or is there some documentation I've missed?


Andy Blower wrote:
> 
> Filip - that looks really good work. 
> 
> I didn't realise new bindings can be created. I'm surprised that you're
> using %d, %s etc rather than the standard {0} {1} ResourceBundle
> parameters. To me it would be nicer expressed like this:  (can you
> overload bindings?)
> 
> ${message:key(param0,param1,...,paramN)}
> 
> The other thing is can the params be the strings from other messages? This
> is something I've done a fair amount in JSP & JSTL to reduce duplication
> of translated text in properties files.
> 
> I'm really not quite sure what "making the message key itself a binding"
> would mean or how it would help, sorry if it's obvious but I'm very new to
> Tapestry. I'll certainly not be doing it myself any time soon, I'm just
> evaluating the framework at the moment.
> 
> Thanks,
> 
> Andy.
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-Expansions---prefixes-tp16448078p16467366.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Expansions & prefixes

Posted by Andy Blower <an...@proquest.co.uk>.
Filip - that looks really good work. 

I didn't realise new bindings can be created. I'm surprised that you're
using %d, %s etc rather than the standard {0} {1} ResourceBundle parameters.
To me it would be nicer expressed like this:  (can you overload bindings?)

${message:key(param0,param1,...,paramN)}

The other thing is can the params be the strings from other messages? This
is something I've done a fair amount in JSP & JSTL to reduce duplication of
translated text in properties files.

I'm really not quite sure what "making the message key itself a binding"
would mean or how it would help, sorry if it's obvious but I'm very new to
Tapestry. I'll certainly not be doing it myself any time soon, I'm just
evaluating the framework at the moment.

Thanks,

Andy.


Filip S. Adamsen-2 wrote:
> 
> I've been thinking about adding support for this to the 
> MessageFormatBindingPrefix found on this wiki page: 
> http://wiki.apache.org/tapestry/Tapestry5HowToAddMessageFormatBindingPrefix
> 
> If you take a look at it the code, MessageFormatBindingFactory in 
> particular, you'll see that making the message key itself a binding 
> wouldn't be too difficult. It should probably default to literal to 
> preserve current behaviour, though.
> 
> You can have a go at it yourself or wait a few days for me to do it.
> 
> -Filip
> 
> On 2008-04-02 20:43, Andy Blower wrote:
>> I'm accessing message catalogs using expansion with a prefix. e.g.
>> ${message:this-is-my-key}
>> 
>> 1) Is there a list of prefixes anywhere, or have I got them all now?
>> (literal, prop, message)
>> 
>> 2) Is there a way of accessing a message with a key that's partially
>> generated by another expansion? 
>> e.g. (this doesn't work obviously, but getProductVariant() is implemented
>> in
>> the page class and its output forms the last segment of the message key) 
>> ${message:product-name-${productVariant}}
>> 
>> 3) Also how can you pass arguments to the messages to replace {0}, {1}
>> etc?
>> 
>> Thanks,
>> 
>> Andy.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-Expansions---prefixes-tp16448078p16467347.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Expansions & prefixes

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
I've been thinking about adding support for this to the 
MessageFormatBindingPrefix found on this wiki page: 
http://wiki.apache.org/tapestry/Tapestry5HowToAddMessageFormatBindingPrefix

If you take a look at it the code, MessageFormatBindingFactory in 
particular, you'll see that making the message key itself a binding 
wouldn't be too difficult. It should probably default to literal to 
preserve current behaviour, though.

You can have a go at it yourself or wait a few days for me to do it.

-Filip

On 2008-04-02 20:43, Andy Blower wrote:
> I'm accessing message catalogs using expansion with a prefix. e.g.
> ${message:this-is-my-key}
> 
> 1) Is there a list of prefixes anywhere, or have I got them all now?
> (literal, prop, message)
> 
> 2) Is there a way of accessing a message with a key that's partially
> generated by another expansion? 
> e.g. (this doesn't work obviously, but getProductVariant() is implemented in
> the page class and its output forms the last segment of the message key) 
> ${message:product-name-${productVariant}}
> 
> 3) Also how can you pass arguments to the messages to replace {0}, {1} etc?
> 
> Thanks,
> 
> Andy.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Expansions & prefixes

Posted by Howard Lewis Ship <hl...@gmail.com>.
On Wed, Apr 2, 2008 at 11:43 AM, Andy Blower <an...@proquest.co.uk> wrote:
>
>  I'm accessing message catalogs using expansion with a prefix. e.g.
>  ${message:this-is-my-key}
>
>  1) Is there a list of prefixes anywhere, or have I got them all now?
>  (literal, prop, message)

http://tapestry.apache.org/tapestry5/tapestry-core/guide/parameters.html

>
>  2) Is there a way of accessing a message with a key that's partially
>  generated by another expansion?
>  e.g. (this doesn't work obviously, but getProductVariant() is implemented in
>  the page class and its output forms the last segment of the message key)
>  ${message:product-name-${productVariant}}

This is something you would delegate to code.  You can inject a
Messages object: that's your component's message catalog (including
message keys inherited from the global application catalog).

>
>  3) Also how can you pass arguments to the messages to replace {0}, {1} etc?

It's based on String.format() not MessageFormat, so its %s and %d, not {0}, etc.

>
>  Thanks,
>
>  Andy.
>  --
>  View this message in context: http://www.nabble.com/T5%3A-Expansions---prefixes-tp16448078p16448078.html
>  Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org