changeset 413:8a4c219fd0ee

Added a method to Resources that returns translated compound messages. flys-artifacts/trunk@1877 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 10 May 2011 11:40:15 +0000
parents 046bd86ae41d
children 0385bcc4229a
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue May 10 10:26:26 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue May 10 11:40:15 2011 +0000
@@ -1,3 +1,8 @@
+2011-05-10  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/resources/Resources.java:
+	  Added new methods to retrieve translated compound messages.
+
 2011-05-10  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/OutGenerator.java: Added a
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java	Tue May 10 10:26:26 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java	Tue May 10 11:40:15 2011 +0000
@@ -1,5 +1,6 @@
 package de.intevation.flys.artifacts.resources;
 
+import java.text.MessageFormat;
 import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
@@ -81,6 +82,33 @@
 
 
     /**
+     * Returns a translated message based on a template specified by <i>key</i>
+     * that has necessary values to be filled in.
+     *
+     * @param meta The CallMeta object.
+     * @param key The key of the template in the resource bundle.
+     * @param def the default value if no template was found with <i>key</i>.
+     * @param args The arguments that are necessary for the template.
+     *
+     * @return a translated string.
+     */
+    public static String getMsg(
+        CallMeta meta,
+        String   key,
+        String   def,
+        Object[] args)
+    {
+        String template = getMsg(meta, key, null);
+
+        if (template == null) {
+            return def;
+        }
+
+        return MessageFormat.format(template, args);
+    }
+
+
+    /**
      * This method returns the translated value for <i>key</i> or <i>def</i> if
      * <i>key</i> is not existing in the resource bundle.
      *

http://dive4elements.wald.intevation.org