3

Folks,

At present we use a set of standard properties files with Struts 2.x to provide our I18N functionality - and for the most part, these do exactly what we need them to. However, there are occasions when it would be great to be able to have individual properties reference other properties in the resource bundle, for example:

name.first=John
name.last=Doe
name.full={name.first} {name.last}

I am aware of several extensions to java.util.Properties that provide these sorts of capabilities such as:

I was wondering if anyone has ever attempted to integrate these somehow into Struts 2.x - is it possible to override the mechanism which handles the parsing of resource bundles?

ShaneK
  • 31
  • 1
  • 1
    I have never used Struts, but for custom ResourceBundles that handle key-expansion you might want to have a look at this: http://stackoverflow.com/questions/2605379/how-do-i-avoid-repetition-in-java-resourcebundle-strings – quaylar Sep 07 '12 at 09:49

1 Answers1

2

There's nothing like this built-in, but IIRC you can set a text provider via:

<bean type="com.opensymphony.xwork2.TextProvider" name="struts"
     class="com.opensymphony.xwork2.TextProviderSupport" scope="default" />

I've never actually done this, but it's a worthy, interesting experiment.

Properties may include arbitrary OGNL, however–you can fake it (verbosely) in the meantime:

name.first=John
name.last=Doe
name.full=%{getText('name.first')} %{getText('name.last')}

(You may also use ${...}, but I prefer %{...} so it's clear it's OGNL.)

I've bookmarked this question for research, there are several cool ideas here.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • i still feel we are having lots of areas where we are either lacking docs or may be they are hidden features of S2. – Umesh Awasthi Sep 07 '12 at 13:51
  • 1
    @UmeshAwasthi Start writing ;) I don't remember how I learned this, I put it in the book, though. I probably figured it out by extrapolating the ability of validation messages to do the same thing. – Dave Newton Sep 07 '12 at 13:57
  • Interesting - I did briefly stumble across TextProviderSupport a few days back when I started looking into this, but didn't appreciate its potential significance/usefulness. I will look into this further now and feed back my results. – ShaneK Sep 10 '12 at 07:35