Rename CmsSession into CmsView, and make it exclusively related to the Display (and...
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / i18n / Msg.java
index dd38c7483563b3cd551cc69ccc25c49802565e0e..b87b7b3d5624b61fe7dc6591bb14f6b66eacf6f4 100644 (file)
@@ -2,9 +2,10 @@ package org.argeo.cms.i18n;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import java.util.Locale;
+import java.util.ResourceBundle;
 
 import org.argeo.cms.CmsException;
-import org.argeo.cms.CmsSession;
 import org.eclipse.rap.rwt.RWT;
 
 /** A single message to be internationalised. */
@@ -53,8 +54,7 @@ public class Msg {
        }
 
        public Object local() {
-               CmsSession cmSession = CmsSession.current.get();
-               Object local = cmSession.local(this);
+               Object local = local(this);
                if (local == null)
                        local = getDefault();
                if (local == null)
@@ -62,6 +62,17 @@ public class Msg {
                return local;
        }
 
+       private static Object local(Msg msg) {
+               String key = msg.getId();
+               int lastDot = key.lastIndexOf('.');
+               String className = key.substring(0, lastDot);
+               String fieldName = key.substring(lastDot + 1);
+               Locale locale = RWT.getLocale();
+               ResourceBundle rb = ResourceBundle.getBundle(className, locale,
+                               msg.getClassLoader());
+               return rb.getString(fieldName);
+       }
+
        public static void init(Class<?> clss) {
                final Field[] fieldArray = clss.getDeclaredFields();
                ClassLoader loader = clss.getClassLoader();