Introduce CMS Message Dialog and improve l10n
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / i18n / Localized.java
index b34cc6ca8e76038f231ed15bc9e127c76ce9726f..535b5f225d04e7cedaa150faf6a286e57ab49f09 100644 (file)
@@ -1,8 +1,27 @@
 package org.argeo.cms.i18n;
 
+import java.text.MessageFormat;
 import java.util.Locale;
 
 /** Localized object. */
 public interface Localized {
-       public Object local(Locale locale);
+       /** Default assumes that this is an {@link Enum} */
+       default Object local(Locale locale) {
+               return LocaleUtils.local((Enum<?>) this, locale);
+       }
+
+       default String lead() {
+               return LocaleUtils.lead(this);
+       }
+
+       default String format(Object[] args) {
+               Locale locale = LocaleUtils.getCurrentLocale();
+               MessageFormat format = new MessageFormat(local(locale).toString(), locale);
+               return format.format(args);
+       }
+
+       default String lead(Locale locale) {
+               return LocaleUtils.lead(local(locale).toString(), locale);
+       }
+
 }