diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java @ 3771:04309ca24614

Locales fix flys-artifacts/trunk@5476 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Sat, 15 Sep 2012 13:42:44 +0000
parents 7f9fe694f8d1
children
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java	Sat Sep 15 07:07:51 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java	Sat Sep 15 13:42:44 2012 +0000
@@ -85,7 +85,6 @@
      * @return the translated message.
      */
     public static String getMsg(CallMeta meta, String key, String def) {
-
         ensureInstance();
 
         Locale[] locales = INSTANCE.getLocales();
@@ -95,10 +94,10 @@
     }
 
     public static String getMsg(
-        CallMeta meta,
-        String   key,
-        Object[] args
-    ) {
+            CallMeta meta,
+            String   key,
+            Object[] args
+            ) {
         return getMsg(meta, key, key, args);
     }
 
@@ -114,10 +113,10 @@
      * @return a translated string.
      */
     public static String getMsg(
-        CallMeta meta,
-        String   key,
-        String   def,
-        Object[] args)
+            CallMeta meta,
+            String   key,
+            String   def,
+            Object[] args)
     {
         String template = getMsg(meta, key, (String)null);
 
@@ -125,22 +124,33 @@
             return def;
         }
 
-        return MessageFormat.format(template, args);
+        return format(meta, template, args);
     }
 
     public static String format(
-        CallMeta   meta,
-        String     key,
-        String     def,
-        Object ... args
-    ) {
+            CallMeta   meta,
+            String     key,
+            String     def,
+            Object ... args
+            ) {
         String template = getMsg(meta, key, (String)null);
 
         if (template == null) {
             template = def;
         }
 
-        return MessageFormat.format(template, args);
+        return format(meta, template, args);
+    }
+
+    /**
+     * Formats the given template using the arguments with respect of the
+     * appropriate locale given by the CallMeta instance.
+     */
+    public static String format(CallMeta meta, String templ, Object ... args) {
+        Locale locale = getLocale(meta);
+        MessageFormat mf = new MessageFormat(templ, locale);
+
+        return mf.format(args, new StringBuffer(), null).toString();
     }
 
     /**

http://dive4elements.wald.intevation.org