Skip to content

Commit 6dd5184

Browse files
committed
优化国际化资源存储解析方法
1 parent f745737 commit 6dd5184

File tree

4 files changed

+36
-80
lines changed

4 files changed

+36
-80
lines changed

dist/include-openlayers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
var excludes = (targetScript.getAttribute('exclude') || "").split(",");
3939
if (!inArray(excludes, 'ol')) {
4040
inputCSS("https://cdn.bootcss.com/openlayers/4.6.4/ol.css");
41-
inputScript("../../web/libs/openlayers/ol-debug.js");
41+
inputScript("https://cdn.bootcss.com/openlayers/4.6.4/ol.js");
4242
}
4343
if (inArray(includes, 'mapv')) {
4444
inputScript("http://mapv.baidu.com/build/mapv.min.js");

examples/js/localization.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,54 @@ var Localization = {
3838

3939
//脚本加载完成标志
4040
var lang = utils.getLanguage();
41+
4142
inputScript(filePathMap[lang], function () {
4243

4344
i18next.init({
4445
lng: lang,
4546
whitelist: ["zh-CN", "en-US"],
4647
fallbackLng: ["zh-CN", "en-US"]
4748
});
49+
if (window.isSite) {
50+
var webResourceURL = `../../web/locales/${lang}/resources.js`
51+
$.get(webResourceURL, function () {
52+
for (var name in window.webResources) {
53+
var subWeb = window.webResources[name];
54+
var subExamples = window.examplesResources[name];
55+
//重名以webResource为准
56+
if (typeof window.webResources[name] == 'object') {
57+
58+
if (!subExamples) {
59+
subExamples = {};
60+
}
61+
for (var name1 in subWeb) {
62+
subExamples[name1] = subWeb[name1];
63+
}
64+
} else {
65+
subExamples[name1] = subWeb[name];
66+
}
67+
68+
}
69+
window.resources = window.examplesResources;
70+
i18next.addResourceBundle(lang, 'translation', window.resources);
71+
callback && callback();
4872

49-
i18next.addResourceBundle(lang, 'translation', window.resources);
73+
})
74+
75+
} else {
76+
window.resources = window.examplesResources;
77+
i18next.addResourceBundle(lang, 'translation', window.resources);
78+
callback && callback();
79+
}
5080

51-
callback && callback();
5281
});
5382

5483
}
5584

5685
//国际化dom中的文本
5786
function localize() {
5887
jqueryI18next.init(i18next, $);
59-
$("html").localize();//翻译页面所有含data-i18n属性的标签的文本
88+
$("html").localize(); //翻译页面所有含data-i18n属性的标签的文本
6089
}
6190

6291
//全局变量挂载

examples/locales/en-US/resources.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
window.resources = {
1+
window.examplesResources = {
22
"app": "SuperMap iClient 9D",
33
"nav": {
44
"home": {

examples/locales/zh-CN/resources.js

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
window.resources = {
1+
window.examplesResources = {
22
"app": "SuperMap iClient 9D",
33
"nav": {
44
"home": {
@@ -27,51 +27,6 @@ window.resources = {
2727
"3dwebgl": {
2828
"_name": "3D-WebGL"
2929
},
30-
"product": {
31-
"_name": "产品",
32-
"introduce": "产品介绍",
33-
"download": "下载",
34-
"guide": "开发指南",
35-
"modules": "模块说明",
36-
"dependence": "相关依赖",
37-
"license": "许可说明",
38-
"features": "技术特点"
39-
},
40-
"guide": {
41-
"_name": "开发指南",
42-
"beginning": "开发入门",
43-
"update": "iClient 8C 升级",
44-
"npm": "npm",
45-
"quickStart": "快速入门",
46-
"projection": "投影",
47-
"ie8": "兼容IE8",
48-
"mapService": "使用地图服务",
49-
"dataService": "使用数据服务",
50-
"spatialAnalystService": "使用空间分析服务",
51-
"networkAnalystService": "使用交通网络分析",
52-
"trafficTransferAnalystService": "使用交通换乘分析",
53-
"processingService": "使用分布式分析服务",
54-
"dataFlow": "使用数据流服务",
55-
"addressMatch": "使用地址匹配服务",
56-
"visualization": "使用可视化",
57-
58-
"install": "安装",
59-
"multiProjection": "如何使用多投影",
60-
"createMap": "创建一幅地图",
61-
"vectorTile": "个性化地图(矢量瓦片)",
62-
"drawSymbolsAndGraphs": "绘制符号与图形",
63-
"areaAndDistanceMeasurement": "面积和距离测量",
64-
"queryMapInformation": "地物查询",
65-
"editMapInformation": "地物编辑",
66-
"thematicMap": "专题图",
67-
"spatialAnalyst": "空间分析",
68-
"networkAnalysis": "网络分析",
69-
"clientComputing": "客户端计算",
70-
"leafletAddressMatch": "地址匹配",
71-
"bigDataAnalysis": "大数据分析",
72-
"leafletVisualization": "可视化"
73-
74-
},
7530
"examples": {
7631
"_name": "示例",
7732
"iServer": "iServer",
@@ -94,35 +49,7 @@ window.resources = {
9449
"mapping": "互联网地图",
9550
"others": "其他",
9651
"3D-WebGL": "3D-WebGL"
97-
},
98-
"more": {
99-
"_name": "更多>>",
100-
"version": {
101-
"_name": "历史版本"
102-
},
103-
"get": {
104-
"_name": "下载",
105-
"stable": "稳定版",
106-
"releases": "Releases",
107-
"source": "源码",
108-
"npm": "npm",
109-
"oldVersions": "历史版本"
110-
},
111-
"language": {
112-
"_name": "语言"
113-
},
114-
"faq": {
115-
"_name": "FAQ"
116-
}
117-
},
118-
"api": {
119-
"_name": "API",
120-
"doc": "文档"
121-
},
122-
"gallery": {
123-
"_name": "Gallery"
124-
},
125-
"soon": "敬请期待"
52+
}
12653
},
12754
"footer": {
12855
"download": "下载",

0 commit comments

Comments
 (0)