diff --git a/designer-base/src/main/java/com/fr/design/i18n/DesignI18nImpl.java b/designer-base/src/main/java/com/fr/design/i18n/DesignI18nImpl.java new file mode 100644 index 0000000000..af759aa3bf --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/i18n/DesignI18nImpl.java @@ -0,0 +1,71 @@ +package com.fr.design.i18n; + +import com.fr.general.GeneralContext; +import com.fr.general.log.MessageFormatter; +import com.fr.locale.DesignI18nProvider; +import com.fr.locale.InterProviderFactory; +import com.fr.locale.LocaleBundle; +import com.fr.locale.LocaleFiles; +import com.fr.locale.LocaleManager; +import com.fr.locale.impl.FineLocaleManager; + +import java.util.List; +import java.util.Locale; + +public class DesignI18nImpl implements DesignI18nProvider { + + private static DesignI18nImpl instance = new DesignI18nImpl(); + + public static DesignI18nImpl getInstance() { + return instance; + } + + private LocaleManager localeManager = FineLocaleManager.create(); + + private DesignI18nImpl() { + addResource("com/fr/design/i18n/main"); + InterProviderFactory.registerDesignI18nProvider(this); + } + + @Override + public String i18nText(String key) { + return localeManager.getLocalBundle(GeneralContext.getLocale()).getText(localeManager, key); + } + + @Override + public String i18nText(String key, Object... args) { + String format = InterProviderFactory.getProvider().getLocText(key); + MessageFormatter.FormattingTuple tuple = MessageFormatter.arrayFormat(format, args); + return localeManager.getLocalBundle(GeneralContext.getLocale()).getText(localeManager, tuple.getMessage()); + } + + @Override + public void addResource(String path) { + localeManager.addResource(path); + } + + @Override + public void removeResource(String path) { + localeManager.removeResource(path); + } + + @Override + public LocaleBundle getLocalBundle(Locale locale) { + return localeManager.getLocalBundle(locale); + } + + @Override + public List getReverseList() { + return localeManager.getReverseList(); + } + + @Override + public List getList() { + return localeManager.getList(); + } + + @Override + public void clear() { + localeManager.clear(); + } +} diff --git a/designer-base/src/main/java/com/fr/design/i18n/Toolkit.java b/designer-base/src/main/java/com/fr/design/i18n/Toolkit.java index 79bb37bb09..d912c7b2d9 100644 --- a/designer-base/src/main/java/com/fr/design/i18n/Toolkit.java +++ b/designer-base/src/main/java/com/fr/design/i18n/Toolkit.java @@ -1,27 +1,12 @@ package com.fr.design.i18n; -import com.fr.general.GeneralContext; -import com.fr.general.log.MessageFormatter; import com.fr.locale.InterProviderFactory; -import com.fr.locale.LocaleManager; -import com.fr.locale.impl.FineLocaleManager; /** * 设计器国际化类,后面会不再依赖InterProviderFactory */ public class Toolkit { - private static LocaleManager localeManager = FineLocaleManager.create(); - - static { - addResource("com/fr/design/i18n/main"); - } - - public static void addResource(String path) { - - localeManager.addResource(path); - } - /** * 设计器国际化方法 * @@ -29,7 +14,7 @@ public class Toolkit { * @return 国际化值 */ public static String i18nText(String key) { - return localeManager.getLocalBundle(GeneralContext.getLocale()).getText(localeManager, key); + return DesignI18nImpl.getInstance().i18nText(key); } /** @@ -41,9 +26,7 @@ public class Toolkit { * @return 国际化值 */ public static String i18nText(String key, Object... args) { - String format = InterProviderFactory.getProvider().getLocText(key); - MessageFormatter.FormattingTuple tuple = MessageFormatter.arrayFormat(format, args); - return localeManager.getLocalBundle(GeneralContext.getLocale()).getText(localeManager, tuple.getMessage()); + return DesignI18nImpl.getInstance().i18nText(key, args); } /** diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java index bac7d72476..2b5e5ab621 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java @@ -27,7 +27,7 @@ import com.fr.design.gui.controlpane.NameObjectCreator; import com.fr.design.gui.controlpane.NameableCreator; import com.fr.design.hyperlink.ReportletHyperlinkPane; import com.fr.design.hyperlink.WebHyperlinkPane; -import com.fr.design.i18n.Toolkit; +import com.fr.design.i18n.DesignI18nImpl; import com.fr.design.javascript.EmailPane; import com.fr.design.javascript.JavaScriptImplPane; import com.fr.design.javascript.ParameterJavaScriptPane; @@ -124,7 +124,7 @@ public class DesignerActivator extends Activator { List markers = rightCollectMutable(InterMutableKey.Path); for (LocaleMarker marker : markers) { if (marker.match(LocaleScope.DESIGN)) { - Toolkit.addResource(marker.getPath()); + DesignI18nImpl.getInstance().addResource(marker.getPath()); } } designerModuleStart();