]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/i18n/Msg.java
Remove unused login entry point
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / i18n / Msg.java
index b87b7b3d5624b61fe7dc6591bb14f6b66eacf6f4..bbbd590cd97356f6365edad5962e261d3ad6d7b1 100644 (file)
@@ -6,7 +6,7 @@ import java.util.Locale;
 import java.util.ResourceBundle;
 
 import org.argeo.cms.CmsException;
-import org.eclipse.rap.rwt.RWT;
+import org.argeo.eclipse.ui.specific.UiContext;
 
 /** A single message to be internationalised. */
 public class Msg {
@@ -48,9 +48,20 @@ public class Msg {
 
        /** When used as the first word of a sentence. */
        public String lead() {
-               String raw = toString();
-               return raw.substring(0, 1).toUpperCase(RWT.getLocale())
-                               + raw.substring(1);
+               return lead(UiContext.getLocale());
+       }
+
+       public String lead(Locale locale) {
+               return lead(this, locale);
+       }
+
+       private static String lead(Msg msg, Locale locale) {
+               String raw = msg.local(locale).toString();
+               return lead(raw, locale);
+       }
+
+       public static String lead(String raw, Locale locale) {
+               return raw.substring(0, 1).toUpperCase(locale) + raw.substring(1);
        }
 
        public Object local() {
@@ -62,12 +73,25 @@ public class Msg {
                return local;
        }
 
+       public Object local(Locale locale) {
+               Object local = local(this, locale);
+               if (local == null)
+                       local = getDefault();
+               if (local == null)
+                       throw new CmsException("No translation found for " + id);
+               return local;
+       }
+
        private static Object local(Msg msg) {
+               Locale locale = UiContext.getLocale();
+               return local(msg, locale);
+       }
+
+       private static Object local(Msg msg, Locale locale) {
                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);