Re: programmatic resources lookup

2015-12-24 Thread Garret Wilson

On 12/24/2015 9:39 AM, Garret Wilson wrote:
... The use of StringResourceModel as you provided almost solved my 
problem, but not quite. When calling from MyPage.java, I had to add 
"this" to the constructor in order for it to pick up resources in the 
MyPage.properties files.


P.S. It's a shame there's no way to do the lookup from a static context, 
e.g. my passing a reference to MyPage.class rather than an actual 
instance of MyPage. But I'll get by. Thanks again for the help.


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: programmatic resources lookup

2015-12-24 Thread Sven Meier

Hi,

the easiest solution would be not to use MessageFormat:

getSession().success(getString("success.message", Model.of(fooBar)));

with:

success.message=Successfully munged the ${}.

If you insist on using MessageFormat, you can just use 
StringResourceModel for that:


getSession().success(new 
StringResourceModel("success.message").setParameters(fooBar).getString());


Have fun
Sven


On 24.12.2015 01:11, Garret Wilson wrote:
I've been away from Wicket for a year, working on other areas of my 
client's code. I'm doing a pass by to add i18n to a page. I have a 
MyPage.properties file with all sorts of properties. I have lots of 
 tags in MyPage.html.


But how do I manually look up one of these values from the resources? 
For example, in MyPage.onAccept() I have something like this:


getSession().success("Successfully munged the " + fooBar + ".");

I want to look up the value from MyPage.properties:

success.message=Successfully munged the {0}.

Looking at the source code of StringResourceModel, it seems I'll have 
to do the following:


1. Get a localizer.
2. Ask the localizer to get the resource string.
3. Escape single quotes.
4. Escape substitution expressions (e.g. ${some.other.property}).
5. Use MessageFormat to substitute the parameters (e.g. fooBar, above).
6. Unescape the substitution expression.
7. Ask the localizer to perform substitution for all the expressions.


Whew! I'm exhausted just writing that. Surely there is a utility 
method that would do that for me?


Garret

P.S. A /single/ method. There should be a single method for this.





-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: programmatic resources lookup

2015-12-24 Thread Garret Wilson
Sven (and Martin, who provided a similar but less complete answer), I'd 
rather not use ${} because in our properties files (for other parts of 
the application unrelated to Wicket) we use ${...} to refer to other 
string resources.


The use of StringResourceModel as you provided almost solved my problem, 
but not quite. When calling from MyPage.java, I had to add "this" to the 
constructor in order for it to pick up resources in the 
MyPage.properties files. But then it worked---thanks!


Garret

On 12/24/2015 2:44 AM, Sven Meier wrote:

Hi,

the easiest solution would be not to use MessageFormat:

getSession().success(getString("success.message", Model.of(fooBar)));

with:

success.message=Successfully munged the ${}.

If you insist on using MessageFormat, you can just use 
StringResourceModel for that:


getSession().success(new 
StringResourceModel("success.message").setParameters(fooBar).getString());


Have fun
Sven


On 24.12.2015 01:11, Garret Wilson wrote:
I've been away from Wicket for a year, working on other areas of my 
client's code. I'm doing a pass by to add i18n to a page. I have a 
MyPage.properties file with all sorts of properties. I have lots of 
 tags in MyPage.html.


But how do I manually look up one of these values from the resources? 
For example, in MyPage.onAccept() I have something like this:


getSession().success("Successfully munged the " + fooBar + ".");

I want to look up the value from MyPage.properties:

success.message=Successfully munged the {0}.

Looking at the source code of StringResourceModel, it seems I'll have 
to do the following:


1. Get a localizer.
2. Ask the localizer to get the resource string.
3. Escape single quotes.
4. Escape substitution expressions (e.g. ${some.other.property}).
5. Use MessageFormat to substitute the parameters (e.g. fooBar, above).
6. Unescape the substitution expression.
7. Ask the localizer to perform substitution for all the expressions.


Whew! I'm exhausted just writing that. Surely there is a utility 
method that would do that for me?


Garret

P.S. A /single/ method. There should be a single method for this.





-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: programmatic resources lookup

2015-12-23 Thread Martin Grigorov
Hi,

String xyz = new StringResourceModel(...).getObject();

P.S. I hope it is short enough!
On Dec 24, 2015 2:11 AM, "Garret Wilson"  wrote:

> I've been away from Wicket for a year, working on other areas of my
> client's code. I'm doing a pass by to add i18n to a page. I have a
> MyPage.properties file with all sorts of properties. I have lots of
>  tags in MyPage.html.
>
> But how do I manually look up one of these values from the resources? For
> example, in MyPage.onAccept() I have something like this:
>
> getSession().success("Successfully munged the " + fooBar + ".");
>
> I want to look up the value from MyPage.properties:
>
> success.message=Successfully munged the {0}.
>
> Looking at the source code of StringResourceModel, it seems I'll have to
> do the following:
>
> 1. Get a localizer.
> 2. Ask the localizer to get the resource string.
> 3. Escape single quotes.
> 4. Escape substitution expressions (e.g. ${some.other.property}).
> 5. Use MessageFormat to substitute the parameters (e.g. fooBar, above).
> 6. Unescape the substitution expression.
> 7. Ask the localizer to perform substitution for all the expressions.
>
>
> Whew! I'm exhausted just writing that. Surely there is a utility method
> that would do that for me?
>
> Garret
>
> P.S. A /single/ method. There should be a single method for this.
>
>