Hi,

It took a while to dive into this but I wrote a simple solution based on
the pattern/matcher example of Tobias and this seems to work well. It only
wraps the default Localizer class in Wicket by overriding the getString
method:

getResourceSettings().setLocalizer(new Localizer()

{

  public String getString(final String key, final Component component,
final IModel<?> model, final Locale locale, final String style, final
IModel<String> defaultValue) throws MissingResourceException

  {

    String value = super.getString(key, component, model, locale, style,
defaultValue);

    StringBuffer output = new StringBuffer();

    final Pattern PLACEHOLDER_PATTERN = Pattern.compile("\\$\\{(.*)\\}");

    Matcher matcher = PLACEHOLDER_PATTERN.matcher(value);


    // Search for other nested keys to replace

    while (matcher.find())

    {

      String replacedPlaceHolder = getString(matcher.group(1), component,
model, locale, style, (String)null);

      matcher.appendReplacement(output, replacedPlaceHolder);

    }

    matcher.appendTail(output);

    return output.toString();

  }

});


Any need for putting this in Wicket? Or maybe somebody has better options
how to do this. I'm all ears but I'm already happy that I could implement
this anyway without patching the Wicket source.


Rob

On Sat, Feb 21, 2015 at 6:14 PM, Tobias Soloschenko <
tobiassolosche...@googlemail.com> wrote:

> Hi,
>
> if it gained not as much interest in the community, but there are still
> some users asking for such an implementation - maybe we can put it into
> wicketstuff-minis?
>
> kind regards
>
> Tobias
>
> P.S.: I also answered the question in stackoverflow. :-)
>
> Am 21.02.15 um 17:59 schrieb Sven Meier:
>
>  Hi,
>>
>> such a feature was asked a few times, e.g.:
>>
>> http://stackoverflow.com/questions/16684200/refer-to-
>> one-property-from-another
>>
>> But apparently it never gained much interest in the community. In my
>> experience you won't find many cases where this is useful anyway.
>>
>> Have fun
>> Sven
>>
>>
>> On 21.02.2015 16:51, Tobias Soloschenko wrote:
>>
>>> Rob,
>>>
>>> we will see what others say and if there is a standard way for this in
>>> wicket. I'm currently testing the implementation - it also replaces keys
>>> found in hierarchy, because Wickets Localizer is going to be used for each
>>> key which is going to be replaced. So the example of your first mail is
>>> also covered.
>>>
>>> kind regards
>>>
>>> Tobias
>>>
>>> Am 21.02.15 um 16:37 schrieb Rob Sonke:
>>>
>>>> Tobias,
>>>>
>>>> Somehow I'm missing your replies in gmail. But thanks for the
>>>> suggestions.
>>>> Using custom models would be a last resort for me. Because I will have
>>>> to
>>>> replace all occurences. I'm somehow hoping to hook into the localizer.
>>>>
>>>> On Sat, Feb 21, 2015 at 2:01 PM, Rob Sonke <r...@tigrou.nl> wrote:
>>>>
>>>>  Hi all,
>>>>>
>>>>> I'm trying to achieve a fairly simple thing within .properties files to
>>>>> avoid a lot of duplicate words through different files.
>>>>>
>>>>> For example there's is a HomePage.properties with:
>>>>> lbl.foo=This is an example text, we love ${lbl.item}
>>>>>
>>>>> And then in MyWebApplication.properties:
>>>>> lbl.item=Wicket
>>>>>
>>>>> But as far as I can see, Wicket tries to resolve the parameters with
>>>>> objects passed to eg StringResourceModel. How can I hook into this and
>>>>> solve this in a nice way?
>>>>>
>>>>> Kind regards,
>>>>> Rob
>>>>>
>>>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to