Browse Source

Merge pull request #346 in DESIGN/design from ~RICHIE/design:release/10.0 to release/10.0

* commit '66cc111ee4a08a82ef37d275dfb0e593b6cf1f58':
  REPORT-10449 插件国际化
final/10.0
richie 6 years ago
parent
commit
73481babe9
  1. 71
      designer-base/src/main/java/com/fr/design/i18n/DesignI18nImpl.java
  2. 21
      designer-base/src/main/java/com/fr/design/i18n/Toolkit.java
  3. 4
      designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java

71
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<LocaleFiles> getReverseList() {
return localeManager.getReverseList();
}
@Override
public List<LocaleFiles> getList() {
return localeManager.getList();
}
@Override
public void clear() {
localeManager.clear();
}
}

21
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);
}
/**

4
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<LocaleMarker> markers = rightCollectMutable(InterMutableKey.Path);
for (LocaleMarker marker : markers) {
if (marker.match(LocaleScope.DESIGN)) {
Toolkit.addResource(marker.getPath());
DesignI18nImpl.getInstance().addResource(marker.getPath());
}
}
designerModuleStart();

Loading…
Cancel
Save