Improve localization framework.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / Localized.java
index 1c7c8e5303143bfc93f5dc0117c9ef0b6411ae91..0a3bd18a862fd73a048a0993242b5d0c00c2d805 100644 (file)
@@ -4,16 +4,23 @@ import java.text.MessageFormat;
 import java.util.Locale;
 
 /** Localized object. */
+@FunctionalInterface
 public interface Localized {
+       String name();
+
        /** Default assumes that this is an {@link Enum} */
-       default Object local(Locale locale) {
-               return LocaleUtils.local((Enum<?>) this, locale);
+       default String local(Locale locale) {
+               return LocaleUtils.local(this, locale);
        }
 
        default String lead() {
                return LocaleUtils.lead(this);
        }
 
+       default String local() {
+               return LocaleUtils.local(this);
+       }
+
        default String format(Object[] args) {
                Locale locale = LocaleUtils.getCurrentLocale();
                MessageFormat format = new MessageFormat(local(locale).toString(), locale);
@@ -21,7 +28,26 @@ public interface Localized {
        }
 
        default String lead(Locale locale) {
-               return LocaleUtils.lead(local(locale).toString(), locale);
+               return LocaleUtils.toLead(local(locale).toString(), locale);
        }
+       
+       static class Untranslated implements Localized {
+               private String msg;
+
+               public Untranslated(String msg) {
+                       super();
+                       this.msg = msg;
+               }
 
+               @Override
+               public String local(Locale locale) {
+                       return msg;
+               }
+
+               @Override
+               public String name() {
+                       return null;
+               }
+
+       }
 }