@gm-mobile/locales 1.1.11 → 1.1.13

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.
Files changed (2) hide show
  1. package/README.md +108 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # @gm-mobile/locales
2
+
3
+ ## 简介
4
+
5
+ @gm-mobile/locales 是 gm-mobile 组件库的国际化(i18n)资源包,提供了多种语言的翻译文件。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install @gm-mobile/locales
11
+ # 或
12
+ yarn add @gm-mobile/locales
13
+ ```
14
+
15
+ ## 包含的语言
16
+
17
+ - **zh** - 简体中文
18
+ - **zh-HK** - 繁体中文(香港)
19
+ - **en** - 英语
20
+ - **th** - 泰语
21
+ - **ug** - 维吾尔语
22
+
23
+ ## 文件结构
24
+
25
+ ```
26
+ locales/
27
+ ├── index.js # 主入口文件
28
+ ├── zh.json # 简体中文翻译
29
+ ├── zh-HK.json # 繁体中文(香港)翻译
30
+ ├── en.json # 英语翻译
31
+ ├── th.json # 泰语翻译
32
+ └── ug.json # 维吾尔语翻译
33
+ ```
34
+
35
+ ## 使用方式
36
+
37
+ ### 在组件中使用
38
+
39
+ 通常配合 `gm-i18n` 库使用:
40
+
41
+ ```jsx
42
+ import { setLocale } from 'gm-i18n'
43
+ import zh from '@gm-mobile/locales/zh.json'
44
+
45
+ // 设置语言
46
+ setLocale('zh', zh)
47
+
48
+ // 使用翻译
49
+ import { t } from 'gm-i18n'
50
+ const title = t('button.confirm') // 获取"确认"的翻译
51
+ ```
52
+
53
+ ### 直接导入使用
54
+
55
+ ```jsx
56
+ import zh from '@gm-mobile/locales/zh.json'
57
+ import en from '@gm-mobile/locales/en.json'
58
+
59
+ const translations = {
60
+ zh,
61
+ en,
62
+ }
63
+
64
+ // 根据用户选择加载对应语言
65
+ const userLang = navigator.language || 'zh'
66
+ const currentTranslation = translations[userLang] || translations.zh
67
+ ```
68
+
69
+ ## 翻译文件格式
70
+
71
+ 每个语言文件都是 JSON 格式,包含键值对:
72
+
73
+ ```json
74
+ {
75
+ "button.confirm": "确认",
76
+ "button.cancel": "取消",
77
+ "dialog.title": "提示",
78
+ ...
79
+ }
80
+ ```
81
+
82
+ ## 开发依赖
83
+
84
+ - **gm-i18n**: ^2.8.0
85
+
86
+ ## 相关包
87
+
88
+ - [@gm-mobile/react](../react/README.md) - React 组件库
89
+ - [@gm-mobile/business](../business/README.md) - 业务组件库
90
+
91
+ ## 贡献翻译
92
+
93
+ 如需添加新的语言支持,请:
94
+
95
+ 1. 创建新的语言文件(如 `ja.json` 用于日语)
96
+ 2. 参考现有语言文件的键名结构
97
+ 3. 确保所有键都有对应的翻译
98
+ 4. 更新 `index.js` 导出
99
+
100
+ ## 许可证
101
+
102
+ ISC
103
+
104
+ ---
105
+
106
+ **版本**: v1.1.12
107
+ **支持语言数**: 5种
108
+ **最后更新**: 2026-03-27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-mobile/locales",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "",
5
5
  "author": "liyatang <liyatang@qq.com>",
6
6
  "homepage": "https://github.com/gmfe/gm-mobile#readme",
@@ -20,5 +20,5 @@
20
20
  "bugs": {
21
21
  "url": "https://github.com/gmfe/gm-mobile/issues"
22
22
  },
23
- "gitHead": "442a85f336ef085e639bb447300e38e8c3feb7df"
23
+ "gitHead": "99f7babda660876d45627b0f0c9378ce655de360"
24
24
  }