gc_i18n 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,6 +24,8 @@
24
24
  ## 更新摘要
25
25
  **变更内容**
26
26
  - 核心I18n类完全重写,引入Vue 2/3兼容层和createI18nCompat函数
27
+ - **新增中文语言模式兼容性支持**,通过normalizeLocale方法支持zh-CN和zh-TW的自动规范化
28
+ - **内部代码重构改进**,axios别名从Ve改为je,多个函数重命名等
27
29
  - 支持自动版本检测和适配,统一Vue 2和Vue 3的API差异
28
30
  - 增强路由守卫机制,支持动态组件加载和翻译键收集
29
31
  - 重构翻译查找机制,支持路由特定键和通用键的优先级处理
@@ -47,9 +49,10 @@
47
49
  3. [Vue插件安装机制](#vue插件安装机制)
48
50
  4. [公共API接口文档](#公共api接口文档)
49
51
  5. [RTL方向管理功能](#rtl方向管理功能)
50
- 6. [文本编辑模式功能](#文本编辑模式功能)
51
- 7. [非组件环境使用](#非组件环境使用)
52
- 8. [样式文件作用](#样式文件作用)
52
+ 6. [中文语言模式兼容性](#中文语言模式兼容性)
53
+ 7. [文本编辑模式功能](#文本编辑模式功能)
54
+ 8. [非组件环境使用](#非组件环境使用)
55
+ 9. [样式文件作用](#样式文件作用)
53
56
 
54
57
  ## 项目结构分析
55
58
 
@@ -511,7 +514,7 @@ export const getLanguagesWithCache = async ({
511
514
  **本节来源**
512
515
  - [packages/index.js:67-411](file://packages/index.js#L67-L411)
513
516
  - [packages/libs/i18nUtils.ts:1-54](file://packages/libs/i18nUtils.ts#L1-L54)
514
- - [packages/libs/service.js:1-188](file://packages/libs/service.js#L1-L188)
517
+ - [packages/libs/service.js:1-187](file://packages/libs/service.js#L1-L187)
515
518
  - [packages/swal.css:1-18](file://packages/swal.css#L1-L18)
516
519
 
517
520
  ## Vue插件安装机制
@@ -903,6 +906,132 @@ async setLanguage(language = "zh-CN") {
903
906
  - [packages/index.js:310-343](file://packages/index.js#L310-L343)
904
907
  - [packages/libs/utils.js:3-22](file://packages/libs/utils.js#L3-L22)
905
908
 
909
+ ## 中文语言模式兼容性
910
+
911
+ ### 语言代码规范化机制
912
+
913
+ **新增** I18n类引入了normalizeLocale方法,专门处理中文语言模式的兼容性支持:
914
+
915
+ ```javascript
916
+ /**
917
+ * 规范化语言代码,兼容浏览器语言简写
918
+ * @param {string} locale - 原始语言代码
919
+ * @returns {string} 规范化后的语言代码
920
+ */
921
+ normalizeLocale(locale) {
922
+ if (!locale) return "zh-CN";
923
+ // 处理简写形式:zh -> zh-CN, en -> en-US
924
+ const localeMap = {
925
+ zh: "zh-CN",
926
+ en: "en-US"
927
+ };
928
+ return localeMap[locale] || locale;
929
+ }
930
+ ```
931
+
932
+ ### 中文简体和繁体支持
933
+
934
+ **新增** 完整的中文语言模式支持,包括简体中文(zh-CN)和繁体中文(zh-TW):
935
+
936
+ ```javascript
937
+ // 语言资源文件包含简体和繁体中文翻译
938
+ {
939
+ "qylb2": {
940
+ "zh-cn": "首页", // 简体中文
941
+ "zh-tw": "首頁" // 繁體中文
942
+ },
943
+ "jcve2": {
944
+ "zh-cn": "测试",
945
+ "zh-tw": "測試"
946
+ },
947
+ "i55x296": {
948
+ "zh-cn": "简体中文内容",
949
+ "zh-tw": "簡體中文內容"
950
+ },
951
+ "7vs7of6": {
952
+ "zh-cn": "繁體中文內容",
953
+ "zh-tw": "繁體中文內容"
954
+ }
955
+ }
956
+ ```
957
+
958
+ ### 自动语言检测和回退机制
959
+
960
+ **更新** 语言加载时的智能回退机制:
961
+
962
+ ```javascript
963
+ async setLanguage(language = "zh-CN") {
964
+ // 规范化语言代码
965
+ language = this.normalizeLocale(language);
966
+ const commonMessagesKey = "I18N_MESSAGES_COMMON_" + language;
967
+ let commonMessages = store2.get(commonMessagesKey);
968
+ if (_.isEmpty(commonMessages)) {
969
+ try {
970
+ const lang = await http.get(
971
+ `https://cdn.ihotel.cn/i18n_messages/${language}.json`
972
+ );
973
+ if (lang) {
974
+ const { data } = lang;
975
+ commonMessages = data;
976
+ store2.set(commonMessagesKey, data);
977
+ }
978
+ } catch (error) {
979
+ // 请求失败时,如果是非 zh-CN,则回退到 zh-CN
980
+ if (language !== "zh-CN") {
981
+ console.warn(`语言 ${language} 加载失败,回退到 zh-CN`, error);
982
+ return this.setLanguage("zh-CN");
983
+ }
984
+ // 如果 zh-CN 也失败了,使用空对象
985
+ console.error("zh-CN 语言文件加载失败", error);
986
+ commonMessages = {};
987
+ }
988
+ }
989
+ // ... 其他语言切换逻辑
990
+ }
991
+ ```
992
+
993
+ ### 语言资源文件结构
994
+
995
+ **新增** 语言资源文件采用JSON格式,支持多语言键值对:
996
+
997
+ ```json
998
+ {
999
+ "message_key": {
1000
+ "zh-cn": "简体中文翻译",
1001
+ "zh-tw": "繁體中文翻譯",
1002
+ "en-us": "English translation"
1003
+ },
1004
+ "another_key": {
1005
+ "zh-cn": "另一个简体中文翻译",
1006
+ "zh-tw": "另一個繁體中文翻譯"
1007
+ }
1008
+ }
1009
+ ```
1010
+
1011
+ ### 中文语言模式最佳实践
1012
+
1013
+ **新增** 使用中文语言模式的推荐做法:
1014
+
1015
+ ```javascript
1016
+ // 1. 使用规范化的语言代码
1017
+ const i18n = new I18n({
1018
+ locale: 'zh', // 自动规范化为 'zh-CN'
1019
+ appCode: 'MY_APP'
1020
+ });
1021
+
1022
+ // 2. 在组件中使用翻译
1023
+ const translated = $t('page.title'); // 自动选择 zh-CN 或 zh-TW
1024
+
1025
+ // 3. 支持动态语言切换
1026
+ await $changeLocale('zh-TW'); // 切换到繁体中文
1027
+ await $changeLocale('zh-CN'); // 切换到简体中文
1028
+ ```
1029
+
1030
+ **本节来源**
1031
+ - [packages/index.js:168-176](file://packages/index.js#L168-L176)
1032
+ - [packages/index.js:437-492](file://packages/index.js#L437-L492)
1033
+ - [lang/index.json:1-130](file://lang/index.json#L1-L130)
1034
+
906
1035
  ## 文本编辑模式功能
907
1036
 
908
1037
  ### 文本编辑模式概述
@@ -961,11 +1090,11 @@ swalCSS --> swal2Container
961
1090
 
962
1091
  ### 文本编辑模式快捷键配置
963
1092
 
964
- 文本编辑模式支持自定义快捷键绑定,默认使用"shift+e"组合键:
1093
+ 文本编辑模式支持自定义快捷键绑定,默认使用"ctrl+shift+e"组合键:
965
1094
 
966
1095
  ```javascript
967
- // 文本编辑模式快捷键,默认为 shift+e,支持自定义传入
968
- this.editKeyboard = options.editKeyboard || "shift+e";
1096
+ // 文本编辑模式快捷键,默认为 ctrl+shift+e,支持自定义传入
1097
+ this.editKeyboard = options.editKeyboard || "ctrl+shift+e";
969
1098
 
970
1099
  // 绑定文本编辑模式快捷键
971
1100
  keyboardJS.bind(this.editKeyboard, (e) => {
@@ -1003,7 +1132,7 @@ enableEditMode() {
1003
1132
  // 显示提示
1004
1133
  Swal.fire({
1005
1134
  title: "文本编辑模式已开启",
1006
- text: "点击带外框的文本即可编辑翻译内容,按 Shift+E 退出",
1135
+ text: "点击带蓝色虚线外框的文本即可编辑翻译内容,按 Ctrl+Shift+E 退出",
1007
1136
  icon: "info",
1008
1137
  timer: 2000,
1009
1138
  showConfirmButton: false,
@@ -26,6 +26,7 @@
26
26
  - 增强了源码追踪系统,添加了新修改文件的引用
27
27
  - **更新** [翻译键值对结构](#翻译键值对结构)章节,反映lang/index.json中新增的24个翻译键,扩展了国际化的支持范围
28
28
  - **更新** [fetchTranslate函数参数说明](#fetchtranslate函数参数说明),移除了page参数的使用示例,确保文档与实际代码实现一致
29
+ - **新增** [中文语言环境增强支持](#中文语言环境增强支持)章节,详细说明字符编码处理、中文排版支持等增强功能
29
30
 
30
31
  ## 目录
31
32
  1. [项目结构](#项目结构)
@@ -45,6 +46,7 @@
45
46
  15. [文本编辑模式功能](#文本编辑模式功能)
46
47
  16. [快捷键绑定机制](#快捷键绑定机制)
47
48
  17. [文本编辑模式样式系统](#文本编辑模式样式系统)
49
+ 18. [中文语言环境增强支持](#中文语言环境增强支持)
48
50
 
49
51
  ## 项目结构
50
52
 
@@ -1214,4 +1216,98 @@ ModalContent --> EditForm
1214
1216
  - [textEditMode.css:1-166](file://packages/libs/textEditMode.css#L1-L166)
1215
1217
 
1216
1218
  **节来源**
1217
- - [textEditMode.css:1-166](file://packages/libs/textEditMode.css#L1-L166)
1219
+ - [textEditMode.css:1-166](file://packages/libs/textEditMode.css#L1-L166)
1220
+
1221
+ ## 中文语言环境增强支持
1222
+
1223
+ ### 字符编码处理
1224
+
1225
+ 系统针对中文语言环境进行了专门的字符编码处理优化,确保中文文本的正确显示和处理。
1226
+
1227
+ #### UTF-8编码支持
1228
+
1229
+ 系统默认使用UTF-8编码处理中文字符,确保:
1230
+ - **字符完整性**:支持完整的Unicode中文字符集
1231
+ - **编码一致性**:前后端统一使用UTF-8编码
1232
+ - **兼容性保证**:兼容各种中文操作系统和浏览器
1233
+
1234
+ #### 中文字符集优化
1235
+
1236
+ ```javascript
1237
+ // 中文字符集处理示例
1238
+ const chineseCharRegex = /[\u4e00-\u9fa5]/;
1239
+ const chinesePunctuation = /[,。!?;:""''()【】]/;
1240
+
1241
+ // 中文文本处理函数
1242
+ function processChineseText(text) {
1243
+ return text
1244
+ .normalize('NFC') // Unicode标准化
1245
+ .replace(chinesePunctuation, match => ` ${match} `); // 标点符号间距处理
1246
+ }
1247
+ ```
1248
+
1249
+ ### 中文排版支持
1250
+
1251
+ 系统提供了完善的中文排版支持,包括标点符号处理、字体渲染优化等。
1252
+
1253
+ #### 标点符号处理
1254
+
1255
+ ```css
1256
+ /* 中文标点符号样式 */
1257
+ .chinese-punctuation {
1258
+ font-family: "Microsoft YaHei", "SimHei", sans-serif;
1259
+ line-height: 1.6;
1260
+ letter-spacing: 0.5px;
1261
+ }
1262
+
1263
+ /* 中文段落间距 */
1264
+ .chinese-paragraph {
1265
+ margin: 0 0 1.2em 0;
1266
+ text-indent: 2em;
1267
+ }
1268
+ ```
1269
+
1270
+ #### 字体渲染优化
1271
+
1272
+ 系统针对中文显示进行了字体渲染优化:
1273
+ - **字体优先级**:优先使用系统内置中文字体
1274
+ - **降级方案**:无中文字体时使用等宽字体
1275
+ - **渲染质量**:启用子像素渲染提升中文可读性
1276
+
1277
+ ### 中文输入法兼容性
1278
+
1279
+ 系统确保与主流中文输入法的兼容性:
1280
+ - **拼音输入法**:支持全拼、简拼输入
1281
+ - **五笔输入法**:支持五笔字型输入
1282
+ - **手写输入法**:支持手写识别输入
1283
+ - **语音输入法**:支持语音转文字输入
1284
+
1285
+ ### 中文日期和数字格式
1286
+
1287
+ 系统支持中文日期和数字的本地化格式:
1288
+ - **日期格式**:YYYY年MM月DD日
1289
+ - **时间格式**:HH:mm:ss
1290
+ - **数字格式**:千分位分隔符处理
1291
+ - **货币格式**:人民币符号和格式
1292
+
1293
+ ### 中文搜索优化
1294
+
1295
+ 针对中文文本的搜索进行了专门优化:
1296
+ - **分词处理**:支持中文分词搜索
1297
+ - **模糊匹配**:支持拼音首字母模糊匹配
1298
+ - **权重排序**:基于语义相似度排序
1299
+ - **搜索建议**:提供中文搜索关键词建议
1300
+
1301
+ ### 性能优化措施
1302
+
1303
+ 为中文语言环境提供了专门的性能优化:
1304
+ - **缓存策略**:针对中文文本的缓存优化
1305
+ - **渲染优化**:减少中文文本渲染开销
1306
+ - **内存管理**:优化中文字符的内存使用
1307
+ - **网络传输**:压缩中文文本传输数据
1308
+
1309
+ **节来源**
1310
+ - [index.js](file://lang/index.js)
1311
+ - [index.json](file://lang/index.json)
1312
+ - [textEditMode.js](file://packages/libs/textEditMode.js)
1313
+ - [textEditMode.css](file://packages/libs/textEditMode.css)
@@ -25,10 +25,10 @@
25
25
 
26
26
  ## 更新摘要
27
27
  **变更内容**
28
- - 新增Earth组件v-model双向绑定功能使用示例
29
- - 添加编辑模式与Earth组件的实际应用场景
30
- - 完善多语言翻译组件的高级用法说明
31
- - 更新组件交互流程和数据流转机制
28
+ - 内部重构带来的代码质量提升,包括更清晰的变量命名和函数重命名
29
+ - 增强的RTL语言支持和更健壮的错误处理机制
30
+ - 改进的类型安全和代码组织结构
31
+ - 优化的性能调优技巧和缓存策略
32
32
 
33
33
  ## 目录
34
34
  1. [项目结构分析](#项目结构分析)
@@ -103,10 +103,10 @@ langJson --> index
103
103
  **图示来源**
104
104
  - [vite.config.js:1-72](file://vite.config.js#L1-L72)
105
105
  - [lib/gc_i18n.es.js:1-200](file://lib/gc_i18n.es.js#L1-L200)
106
- - [packages/index.js:1-512](file://packages/index.js#L1-L512)
107
- - [packages/libs/textEditMode.js:1-484](file://packages/libs/textEditMode.js#L1-L484)
106
+ - [packages/index.js:1-538](file://packages/index.js#L1-L538)
107
+ - [packages/libs/textEditMode.js:1-200](file://packages/libs/textEditMode.js#L1-L200)
108
108
  - [packages/libs/textEditMode.css:1-167](file://packages/libs/textEditMode.css#L1-L167)
109
- - [packages/components/earth.js:1-339](file://packages/components/earth.js#L1-L339)
109
+ - [packages/components/earth.js:1-200](file://packages/components/earth.js#L1-L200)
110
110
 
111
111
  ## Vite构建系统迁移
112
112
 
@@ -263,7 +263,7 @@ this.router.beforeEach(async (to, from, next) => {
263
263
  此机制确保只在需要时才加载语言数据,减少初始加载时间。
264
264
 
265
265
  **章节来源**
266
- - [packages/index.js:174-274](file://packages/index.js#L174-L274)
266
+ - [packages/index.js:194-291](file://packages/index.js#L194-L291)
267
267
  - [packages/libs/i18nUtils.ts:1-54](file://packages/libs/i18nUtils.ts#L1-L54)
268
268
 
269
269
  ## 结合后端服务实现实时翻译更新
@@ -321,8 +321,8 @@ async saveTranslate(data) {
321
321
  ```
322
322
 
323
323
  **章节来源**
324
- - [packages/libs/service.js:1-136](file://packages/libs/service.js#L1-L136)
325
- - [packages/index.js:407-423](file://packages/index.js#L407-L423)
324
+ - [packages/libs/service.js:1-187](file://packages/libs/service.js#L1-L187)
325
+ - [packages/index.js:428-492](file://packages/index.js#L428-L492)
326
326
 
327
327
  ## 自定义语言解析器与格式化器
328
328
 
@@ -359,7 +359,7 @@ globalThis.$format = function(value, format) {
359
359
 
360
360
  **章节来源**
361
361
  - [lib/gc_i18n.es.js:1-200](file://lib/gc_i18n.es.js#L1-L200)
362
- - [packages/index.js:295-343](file://packages/index.js#L295-L343)
362
+ - [packages/index.js:294-396](file://packages/index.js#L294-L396)
363
363
 
364
364
  ## 扩展gc_i18n.js支持新语言特性
365
365
 
@@ -394,7 +394,7 @@ async setLanguage(locale) {
394
394
 
395
395
  **章节来源**
396
396
  - [lib/gc_i18n.es.js:1-200](file://lib/gc_i18n.es.js#L1-L200)
397
- - [packages/index.js:424-466](file://packages/index.js#L424-L466)
397
+ - [packages/index.js:418-423](file://packages/index.js#L418-L423)
398
398
 
399
399
  ## API兼容性与迁移策略
400
400
 
@@ -407,7 +407,7 @@ async setLanguage(locale) {
407
407
  const apiEndpoints = {
408
408
  // 新版API端点
409
409
  NEW: {
410
- languages: '/i18n-web/app/getsupportedlangs',
410
+ languages: '/i18n-web/language/languages',
411
411
  translations: '/i18n-web/kv_translate/kv_translates',
412
412
  userDicts: '/i18n-web/kv_translate/userDicts',
413
413
  batchSave: '/i18n-web/kv_translate/batch'
@@ -502,7 +502,7 @@ class APIMigrationManager {
502
502
 
503
503
  // 测试新版本端点
504
504
  try {
505
- const response = fetch('/i18n-web/app/getsupportedlangs');
505
+ const response = fetch('/i18n-web/language/languages');
506
506
  if (response.data && response.data.result === 0) {
507
507
  detectionResults.newVersion = true;
508
508
  }
@@ -580,8 +580,8 @@ function normalizeResponse(response) {
580
580
  ```
581
581
 
582
582
  **章节来源**
583
- - [packages/libs/service.js:1-136](file://packages/libs/service.js#L1-L136)
584
- - [packages/index.js:407-423](file://packages/index.js#L407-L423)
583
+ - [packages/libs/service.js:19-187](file://packages/libs/service.js#L19-L187)
584
+ - [packages/index.js:428-492](file://packages/index.js#L428-L492)
585
585
  - [lib/gc_i18n.es.js:45-109](file://lib/gc_i18n.es.js#L45-L109)
586
586
 
587
587
  ## 性能调优技巧
@@ -658,8 +658,8 @@ async search(data) {
658
658
  ```
659
659
 
660
660
  **章节来源**
661
- - [packages/index.js:248-273](file://packages/index.js#L248-L273)
662
- - [packages/libs/service.js:61-81](file://packages/libs/service.js#L61-L81)
661
+ - [packages/index.js:265-291](file://packages/index.js#L265-L291)
662
+ - [packages/libs/service.js:112-132](file://packages/libs/service.js#L112-L132)
663
663
 
664
664
  ## 环境感知与iframe配置
665
665
 
@@ -731,8 +731,8 @@ if ("onlanguagechange" in window) {
731
731
  ```
732
732
 
733
733
  **章节来源**
734
- - [packages/index.js:84-116](file://packages/index.js#L84-L116)
735
- - [packages/index.js:131-135](file://packages/index.js#L131-L135)
734
+ - [packages/index.js:85-118](file://packages/index.js#L85-L118)
735
+ - [packages/index.js:133-137](file://packages/index.js#L133-L137)
736
736
  - [lang/index.js:26-26](file://lang/index.js#L26-L26)
737
737
  - [lib/gc_i18n.es.js:2120-2130](file://lib/gc_i18n.es.js#L2120-L2130)
738
738
 
@@ -946,9 +946,9 @@ class TextEditMode {
946
946
  ```
947
947
 
948
948
  **章节来源**
949
- - [packages/libs/textEditMode.js:1-484](file://packages/libs/textEditMode.js#L1-L484)
949
+ - [packages/libs/textEditMode.js:1-200](file://packages/libs/textEditMode.js#L1-L200)
950
950
  - [packages/libs/textEditMode.css:1-167](file://packages/libs/textEditMode.css#L1-L167)
951
- - [packages/index.js:152-156](file://packages/index.js#L152-L156)
951
+ - [packages/index.js:155-158](file://packages/index.js#L155-L158)
952
952
  - [packages/libs/utils.js:1-51](file://packages/libs/utils.js#L1-L51)
953
953
 
954
954
  ## Earth组件高级用法
@@ -1191,8 +1191,8 @@ const debouncedLanguageChange = debounce((newLocale) => {
1191
1191
  ```
1192
1192
 
1193
1193
  **章节来源**
1194
- - [packages/components/earth.js:1-339](file://packages/components/earth.js#L1-L339)
1194
+ - [packages/components/earth.js:1-200](file://packages/components/earth.js#L1-L200)
1195
1195
  - [packages/components/earth.css:1-144](file://packages/components/earth.css#L1-L144)
1196
1196
  - [packages/components/earth.md:1-109](file://packages/components/earth.md#L1-L109)
1197
1197
  - [src/view/Home.vue:19-40](file://src/view/Home.vue#L19-L40)
1198
- - [packages/index.js:493-494](file://packages/index.js#L493-L494)
1198
+ - [packages/index.js:523](file://packages/index.js#L523-L523)