Browse Source

CHART-16853 处理富文本国际化

final/10.0
Qinghui.Liu 4 years ago
parent
commit
67bc9edf4f
  1. 56
      designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartRichEditorPane.java
  2. 19
      designer-chart/src/main/resources/com/fr/design/editor/rich_editor.html
  3. 2
      designer-chart/src/main/resources/com/fr/design/editor/script/editor.js
  4. 6
      designer-chart/src/main/resources/com/fr/design/editor/script/editor.model.js
  5. 15
      designer-chart/src/main/resources/com/fr/design/editor/script/enums.js
  6. 123
      designer-chart/src/main/resources/com/fr/design/editor/script/i18n.js

56
designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartRichEditorPane.java

@ -1,6 +1,10 @@
package com.fr.van.chart.designer.component; package com.fr.van.chart.designer.component;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager;
import com.fr.design.ui.ModernUIPane; import com.fr.design.ui.ModernUIPane;
import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.chart.base.AttrTooltipRichText; import com.fr.plugin.chart.base.AttrTooltipRichText;
import com.fr.plugin.chart.type.TextAlign; import com.fr.plugin.chart.type.TextAlign;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -9,7 +13,10 @@ import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter; import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter;
import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent; import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class VanChartRichEditorPane { public class VanChartRichEditorPane {
@ -21,6 +28,25 @@ public class VanChartRichEditorPane {
private static ModernUIPane<RichEditorModel> richEditorPane; private static ModernUIPane<RichEditorModel> richEditorPane;
private static Browser browser; private static Browser browser;
public static void initRichEditorPane() {
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("VanChartRichEditor"));
try {
singleThreadExecutor.submit(new Runnable() {
@Override
public void run() {
try {
richEditorPane = initPane(new RichEditorModel());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
});
} finally {
singleThreadExecutor.shutdown();
}
}
public static ModernUIPane<RichEditorModel> createRichEditorPane(AttrTooltipRichText richEditor) { public static ModernUIPane<RichEditorModel> createRichEditorPane(AttrTooltipRichText richEditor) {
RichEditorModel model = getRichEditorModel(richEditor); RichEditorModel model = getRichEditorModel(richEditor);
@ -40,6 +66,11 @@ public class VanChartRichEditorPane {
browser = event.getBrowser(); browser = event.getBrowser();
browser.getCacheStorage().clearCache(); browser.getCacheStorage().clearCache();
browser.executeJavaScript(IOUtils.readResourceAsString("/com/fr/web/ui/fineui.min.js"));
browser.executeJavaScript(IOUtils.readResourceAsString("/com/fr/design/editor/script/i18n.js"));
browser.executeJavaScript(generateTransformI18nJS());
browser.executeJavaScript(IOUtils.readResourceAsString("/com/fr/web/ui/materials.min.js"));
JSValue ns = browser.executeJavaScriptAndReturnValue("window." + namespace); JSValue ns = browser.executeJavaScriptAndReturnValue("window." + namespace);
ns.asObject().setProperty(variable, model); ns.asObject().setProperty(variable, model);
} }
@ -87,12 +118,27 @@ public class VanChartRichEditorPane {
return new RichEditorModel(content, richText.isAuto(), paramsStr.toString(), initParams, align); return new RichEditorModel(content, richText.isAuto(), paramsStr.toString(), initParams, align);
} }
public static String generateTransformI18nJS() {
String language = "zh_CN";
Locale locale = DesignerEnvManager.getEnvManager().getLanguage();
if (locale != null) {
language = locale.toString();
}
return "!(function () { window.transformI18n && window.transformI18n('" + language + "' || 'zh_CN'); }());";
}
public static class RichEditorModel { public static class RichEditorModel {
private String content; private String content = StringUtils.EMPTY;
private boolean auto; private boolean auto = true;
private String params; private String params = StringUtils.EMPTY;
private String initParams; private String initParams = StringUtils.EMPTY;
private String align; private String align = TextAlign.LEFT.getAlign();
public RichEditorModel() {
}
public RichEditorModel(String content, boolean auto, String params, String initParams, String align) { public RichEditorModel(String content, boolean auto, String params, String initParams, String align) {
this.content = content; this.content = content;

19
designer-chart/src/main/resources/com/fr/design/editor/rich_editor.html

@ -5,26 +5,9 @@
<title></title> <title></title>
<link rel="stylesheet" type="text/css" href="http://fanruan.design/fineui/2.0/fineui.min.css"/> <link rel="stylesheet" type="text/css" href="http://fanruan.design/fineui/2.0/fineui.min.css"/>
<link rel="stylesheet" type="text/css" href="./rich_editor.css"/> <link rel="stylesheet" type="text/css" href="./rich_editor.css"/>
<script src="http://fanruan.design/fineui/2.0/fineui.js"></script>
<script src="https://fanruan.design/fineui/materials.bundle.min.js"></script>
</head> </head>
<body> <body>
<script> <script src="script/enums.js"></script>
BICst.RICH_TEXT_INFO = {
DATA_ID: "data-id",
DATA_NAME: "data-name",
DATA_FULL_NAME: "data-full-name",
DATA_ORIGIN_ID: "data-origin-id",
DATA_ORIGIN_NAME: "data-origin-name",
DATA_ORIGIN_FULL_NAME: "data-origin-full-name",
DATA_IS_INSERT_PARAM: "data-is-insert-param",
DATA_IS_MISSING_FIELD: "data-is-missing-field",
DATA_UN_VALID: "data-unvalid",
NAME: "name",
ALT: "alt",
SRC: "src"
};
</script>
<script src="script/insertcombo/item/item.js"></script> <script src="script/insertcombo/item/item.js"></script>
<script src="script/insertcombo/combo.insert_param.js"></script> <script src="script/insertcombo/combo.insert_param.js"></script>
<script src="script/insertcombo/combo.insert_param.model.js"></script> <script src="script/insertcombo/combo.insert_param.model.js"></script>

2
designer-chart/src/main/resources/com/fr/design/editor/script/editor.js

@ -52,7 +52,7 @@
type: "bi.htape", type: "bi.htape",
items: [{ items: [{
type: "bi.label", type: "bi.label",
text: "字体样式: ", text: BI.i18nText("BI-Design_Font_Style") + ": ",
textAlign: "left", textAlign: "left",
width: 70 width: 70
}, { }, {

6
designer-chart/src/main/resources/com/fr/design/editor/script/editor.model.js

@ -17,8 +17,9 @@
fontStyleItems: function () { fontStyleItems: function () {
return [{ return [{
type: "bi.single_select_radio_item", type: "bi.single_select_radio_item",
text: "自动", text: BI.i18nText("BI-Basic_Auto"),
hgap: 5, hgap: 5,
width: 50,
logic: { logic: {
dynamic: true dynamic: true
}, },
@ -26,8 +27,9 @@
selected: this.options.isAuto selected: this.options.isAuto
}, { }, {
type: "bi.single_select_radio_item", type: "bi.single_select_radio_item",
text: "自定义", text: BI.i18nText("BI-Basic_Custom"),
hgap: 5, hgap: 5,
width: 60,
logic: { logic: {
dynamic: true dynamic: true
}, },

15
designer-chart/src/main/resources/com/fr/design/editor/script/enums.js

@ -0,0 +1,15 @@
window.BICst = window.BICst || {};
BICst.RICH_TEXT_INFO = {
DATA_ID: "data-id",
DATA_NAME: "data-name",
DATA_FULL_NAME: "data-full-name",
DATA_ORIGIN_ID: "data-origin-id",
DATA_ORIGIN_NAME: "data-origin-name",
DATA_ORIGIN_FULL_NAME: "data-origin-full-name",
DATA_IS_INSERT_PARAM: "data-is-insert-param",
DATA_IS_MISSING_FIELD: "data-is-missing-field",
DATA_UN_VALID: "data-unvalid",
NAME: "name",
ALT: "alt",
SRC: "src"
};

123
designer-chart/src/main/resources/com/fr/design/editor/script/i18n.js

@ -0,0 +1,123 @@
!(function () {
var chinese = {
"BI-Design_Font_Style": "字体样式",
"BI-Font_Size": "字号",
"BI-Basic_Auto": "自动",
"BI-Basic_Custom": "自定义",
"BI-Basic_Default": "默认",
"BI-Basic_Sim_Hei": "黑体",
"BI-Basic_Sim_Sun": "宋体",
"BI-Basic_Fang_Song": "仿宋",
"BI-Basic_Kai_Ti": "楷体",
"BI-Basic_Bold": "加粗",
"BI-Basic_Italic": "斜体",
"BI-Basic_Underline": "下划线",
"BI-Basic_Font_Color": "文字颜色",
"BI-Word_Align_Left": "文字居左",
"BI-Word_Align_Center": "文字居中",
"BI-Word_Align_Right": "文字居右"
};
var taiwan = {
"BI-Design_Font_Style": "字體樣式",
"BI-Font_Size": "字號",
"BI-Basic_Auto": "自動",
"BI-Basic_Custom": "自定義",
"BI-Basic_Default": "默認",
"BI-Basic_Sim_Hei": "黑體",
"BI-Basic_Sim_Sun": "宋體",
"BI-Basic_Fang_Song": "仿宋",
"BI-Basic_Kai_Ti": "楷體",
"BI-Basic_Bold": "加粗",
"BI-Basic_Italic": "斜體",
"BI-Basic_Underline": "下劃線",
"BI-Basic_Font_Color": "文字顏色",
"BI-Word_Align_Left": "文字居左",
"BI-Word_Align_Center": "文字居中",
"BI-Word_Align_Right": "文字居右"
};
var english = {
"BI-Design_Font_Style": "Font style",
"BI-Font_Size": "Font size",
"BI-Basic_Auto": "auto",
"BI-Basic_Custom": "custom",
"BI-Basic_Default": "default",
"BI-Basic_Sim_Hei": "Sim_Hei",
"BI-Basic_Sim_Sun": "Sim_Sun",
"BI-Basic_Fang_Song": "Fang_Song",
"BI-Basic_Kai_Ti": "Kai_Ti",
"BI-Basic_Bold": "Bold",
"BI-Basic_Italic": "Italic",
"BI-Basic_Underline": "UnderLine",
"BI-Basic_Font_Color": "Font Color",
"BI-Word_Align_Left": "Align Left",
"BI-Word_Align_Center": "Align Center",
"BI-Word_Align_Right": "Align Right"
};
var japanese = {
"BI-Design_Font_Style": "フォントスタイル",
"BI-Font_Size": "フォントサイズ",
"BI-Basic_Auto": "自動",
"BI-Basic_Custom": "カスタマイズ",
"BI-Basic_Default": "デフォルト",
"BI-Basic_Sim_Hei": "黒い体",
"BI-Basic_Sim_Sun": "ソンティ",
"BI-Basic_Fang_Song": "イミテーションソング",
"BI-Basic_Kai_Ti": "イタリック",
"BI-Basic_Bold": "大胆な",
"BI-Basic_Italic": "イタリック",
"BI-Basic_Underline": "アンダースコア",
"BI-Basic_Font_Color": "テキストの色",
"BI-Word_Align_Left": "左のテキスト",
"BI-Word_Align_Center": "テキスト中心",
"BI-Word_Align_Right": "右のテキスト"
};
var korean = {
"BI-Design_Font_Style": "글꼴 스타일",
"BI-Font_Size": "글꼴 크기",
"BI-Basic_Auto": "자동적 인",
"BI-Basic_Custom": "맞춤 설정",
"BI-Basic_Default": "기본",
"BI-Basic_Sim_Hei": "블랙 바디",
"BI-Basic_Sim_Sun": "송티",
"BI-Basic_Fang_Song": "모조 노래",
"BI-Basic_Kai_Ti": "기울임 꼴",
"BI-Basic_Bold": "굵게",
"BI-Basic_Italic": "이탤릭체",
"BI-Basic_Underline": "밑줄",
"BI-Basic_Font_Color": "텍스트 색상",
"BI-Word_Align_Left": "왼쪽 텍스트",
"BI-Word_Align_Center": "텍스트 중심",
"BI-Word_Align_Right": "오른쪽 텍스트"
};
function transformI18n(language) {
var BI = window.BI;
if (BI == null) {
return;
}
if (language == null) {
BI.addI18n(chinese);
}
if (language.indexOf('zh_TW') > -1) {
BI.addI18n(taiwan);
} else if (language.indexOf('en_US') > -1) {
BI.addI18n(english);
} else if (language.indexOf('ja_JP') > -1) {
BI.addI18n(japanese);
} else if (language.indexOf('ko_KR') > -1) {
BI.addI18n(korean);
} else {
BI.addI18n(chinese);
}
}
window.transformI18n = transformI18n;
}());
Loading…
Cancel
Save