Browse Source

DEC-3146 新平台浏览器设置成英文的后台会报NPE

1、整理所有国际化加载相关的代码,统一到core中去加载
2、懒加载:Locale懒加载,文件懒加载
3、后添加的文件覆盖先加载的(即默认插件的国际化可以覆盖原始的国际化)
4、支持remove操作,禁用掉插件后国际化自动清除
master
ju 7 years ago
parent
commit
e15f0e1bd0
  1. 49
      designer-base/src/main/java/com/fr/design/actions/file/LocalePane.java

49
designer-base/src/main/java/com/fr/design/actions/file/LocalePane.java

@ -12,10 +12,10 @@ import com.fr.design.gui.itextfield.UITextField;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.general.GeneralUtils; import com.fr.general.GeneralUtils;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.locale.InterProviderFactory;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.bridge.StableFactory;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.resource.WorkResourceOutputStream; import com.fr.workspace.resource.WorkResourceOutputStream;
@ -37,7 +37,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set; import java.util.Set;
import java.util.Vector; import java.util.Vector;
@ -122,42 +121,25 @@ public class LocalePane extends BasicPane {
private void initPredefinedProperties() { private void initPredefinedProperties() {
Map<Locale, String> supportLocaleMap = Inter.getSupportLocaleMap(); Map<Locale, String> supportLocaleMap = InterProviderFactory.getProvider().getSupportLocaleMap();
String[] localeFiles = StableFactory.getLocaleFiles();
Map<String, String> map;
List<String> sortKeys = new ArrayList<String>(); List<String> sortKeys = new ArrayList<String>();
for (String path : localeFiles) { map = InterProviderFactory.getProvider().getLocalBundle(Locale.SIMPLIFIED_CHINESE).getMap();
ResourceBundle chineseBundle = loadResourceBundle(path, Locale.SIMPLIFIED_CHINESE); sortKeys.addAll(map.keySet());
sortKeys.addAll(chineseBundle.keySet());
}
Collections.sort(sortKeys); Collections.sort(sortKeys);
Map<Locale, List<ResourceBundle>> localeResourceBundleMap = new HashMap<Locale, List<ResourceBundle>>();
for (Map.Entry<Locale, String> entry : supportLocaleMap.entrySet()) {
Locale locale = entry.getKey();
List<ResourceBundle> list = new ArrayList<>();
for (String path : localeFiles) {
ResourceBundle chineseBundle = loadResourceBundle(path, locale);
list.add(chineseBundle);
}
localeResourceBundleMap.put(locale, list);
}
Map<Locale, Vector<String>> data = new HashMap<Locale, Vector<String>>(); Map<Locale, Vector<String>> data = new HashMap<Locale, Vector<String>>();
for (Map.Entry<Locale, List<ResourceBundle>> entry : localeResourceBundleMap.entrySet()) { for (Locale locale : supportLocaleMap.keySet()) {
Vector<String> column = new Vector<String>(); Vector<String> column = new Vector<String>();
List<ResourceBundle> rbs = entry.getValue();
for (String key : sortKeys) { for (String key : sortKeys) {
column.add(readText(rbs, key)); column.add(InterProviderFactory.getProvider().getLocText(key));
}
data.put(entry.getKey(), column);
} }
data.put(locale, column);
}
Vector<String> keyVector = new Vector<String>(); Vector<String> keyVector = new Vector<String>();
keyVector.addAll(sortKeys); keyVector.addAll(sortKeys);
@ -168,19 +150,6 @@ public class LocalePane extends BasicPane {
} }
} }
private String readText(List<ResourceBundle> rbs, String key) {
for (ResourceBundle rb : rbs) {
if (rb.containsKey(key)) {
return rb.getString(key);
}
}
return null;
}
private ResourceBundle loadResourceBundle(String dir, Locale locale) {
return ResourceBundle.getBundle(dir, locale, Inter.class.getClassLoader());
}
private void initCustomProperties() throws Exception { private void initCustomProperties() throws Exception {
FileNode[] fileNodes = FRContext.getFileNodes().list(ProjectConstants.LOCALE_NAME); FileNode[] fileNodes = FRContext.getFileNodes().list(ProjectConstants.LOCALE_NAME);

Loading…
Cancel
Save