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
<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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]