1. opensymphony
  2. webwork

Commits

jcarreira  committed 2c84c41

WW-552: You can specify default resource bundles to be loaded at startup in webwork.properties by giving a comma separated list of properties files paths in the property webwork.custom.i18n.resources

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@498573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits 1cce4e6
  • Branches master

Comments (0)

Files changed (6)

File src/java/com/opensymphony/webwork/config/DefaultConfiguration.java

View file
  */
 package com.opensymphony.webwork.config;
 
+import com.opensymphony.xwork.util.LocalizedTextUtil;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
  * Default implementation of Configuration - creates and delegates to other configurations by using an internal
  * {@link DelegatingConfiguration}.
  *
+ *
  * @author Rickard Öberg
  * @author Jason Carreira
  * @author Bill Lynch (docs)
      * in this class will call that configuration object.
      */
     public DefaultConfiguration() {
-        // Create default implementations
+        // Create default implementations 
         // Use default properties and webwork.properties
         ArrayList list = new ArrayList();
 
             config = new DelegatingConfiguration((Configuration[]) list.toArray(configList));
         } catch (IllegalArgumentException e) {
         }
+
+        // Add addtional list of i18n global resource bundles
+        StringTokenizer bundleFiles = new StringTokenizer((String) config.getImpl("webwork.custom.i18n.resources"), ",");
+
+        while (bundleFiles.hasMoreTokens()) {
+            String name = bundleFiles.nextToken();
+
+            try {
+                log.info("Loading global messages from " + name);
+                LocalizedTextUtil.addDefaultResourceBundle(name);
+            } catch (Exception e) {
+                log.error("Could not find " + name + ".properties. Skipping");
+            }
+        }
     }
 
     //~ Methods ////////////////////////////////////////////////////////////////

File src/java/com/opensymphony/webwork/default.properties

View file
 webwork.url.http.port = 80
 webwork.url.https.port = 443
 
+### Load custom default resource bundles
+#webwork.custom.i18n.resources=testmessages,testmessages2

File src/test/com/opensymphony/webwork/config/ConfigurationTest.java

View file
  */
 package com.opensymphony.webwork.config;
 
+import com.opensymphony.xwork.util.LocalizedTextUtil;
+
 import junit.framework.TestCase;
 
 import java.util.Iterator;
         assertEquals("de", locale.getLanguage());
 
         int count = getKeyCount();
-        assertEquals(15, count);
+        assertEquals(16, count);
+    }
+
+    public void testDefaultResourceBundlesLoaded() {
+        assertEquals("testmessages,testmessages2", Configuration.getString("webwork.custom.i18n.resources"));
+        assertEquals("This is a test message", LocalizedTextUtil.findDefaultText("default.testmessage", Locale.getDefault()));
+        assertEquals("This is another test message", LocalizedTextUtil.findDefaultText("default.testmessage2", Locale.getDefault()));
     }
 
     public void testSetConfiguration() {

File src/test/testmessages.properties

View file
+default.testmessage=This is a test message

File src/test/testmessages2.properties

View file
+default.testmessage2=This is another test message

File src/test/webwork.properties

View file
 # added the MockTag to the path of Tags that the TagDirective will search through
 webwork.velocity.tag.path = com.opensymphony.webwork.views.velocity.ui, org.displaytag.tags
 
-webwork.ui.templateDir = template
+webwork.ui.templateDir = template
+
+### Load custom default resource bundles
+webwork.custom.i18n.resources=testmessages,testmessages2