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
<wicket:message key="fooBar"> 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: [email protected]
For additional commands, e-mail: [email protected]