Search code examples
javastruts2internationalizationquartz-schedulerresourcebundle

Using Struts2 i18n feature in Quartz jobs


Our web application is based on Struts2. We get all message resource by using struts getText() in actions and Struts2 <s:text name=""/> in JSP.

The application also has some Quartz job which run at certain times. Is it possible that we use Struts2 classes in Quartz jobs to get the proper message resources from message bundles.

Please consider that we configured lots of message files with Struts and also, we use Struts2 ability to override certain message resources (Struts 2 override resource messages keys) so we prefer to use Struts2 way to get i18n messages instead of java build in feature.


Solution

  • You can use one of the methods in LocalizedTextUtil class to get localized messages from resource bundles in Quartz jobs.

    For example take a look at:

    LocalizedTextUtil#findDefaultText(String aTextName, Locale locale)
    

    or

    LocalizedTextUtil#findText(Class aClass, String aTextName, Locale locale)