tang-ui-x 1.1.1 → 1.1.2

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 (87) hide show
  1. package/README.md +1003 -0
  2. package/components/TActionSheet/index.uvue +15 -2
  3. package/components/TCollapse/index.uvue +1 -1
  4. package/components/TCollapse/type.uts +3 -1
  5. package/components/TCollapseItem/index.uvue +22 -26
  6. package/components/TDialog/index.uvue +19 -4
  7. package/components/TEmpty/index.uvue +28 -14
  8. package/components/TForm/index.uvue +30 -9
  9. package/components/TForm/type.uts +4 -0
  10. package/components/TInput/index.uvue +24 -5
  11. package/components/TInput/type.uts +10 -0
  12. package/components/TPicker/index.uvue +26 -6
  13. package/components/TSearchBar/index.uvue +19 -4
  14. package/composables/i18n/error.uts +82 -0
  15. package/composables/i18n/index.uts +188 -0
  16. package/composables/i18n/manager-demo.uts +104 -0
  17. package/composables/i18n/manager.test.uts +182 -0
  18. package/composables/i18n/manager.uts +336 -0
  19. package/composables/i18n/register-demo.uts +125 -0
  20. package/composables/i18n/task22-verification.uts +198 -0
  21. package/composables/i18n/task23-verification.uts +343 -0
  22. package/composables/i18n/task8-demo.uts +93 -0
  23. package/composables/i18n/task8-verification.uts +98 -0
  24. package/composables/i18n/test-task23.uts +9 -0
  25. package/composables/i18n/types.uts +46 -0
  26. package/composables/i18n/useI18n-verification.uts +105 -0
  27. package/composables/i18n/validation-demo.uts +45 -0
  28. package/composables/i18n/validation-test.uts +106 -0
  29. package/composables/useI18n.uts +77 -0
  30. package/index.uts +23 -0
  31. package/locales/cross-platform-verification.uts +510 -0
  32. package/locales/en-US/actionSheet.json +3 -0
  33. package/locales/en-US/common.json +10 -0
  34. package/locales/en-US/dialog.json +5 -0
  35. package/locales/en-US/empty.json +5 -0
  36. package/locales/en-US/errorState.json +5 -0
  37. package/locales/en-US/examplePages.json +1236 -0
  38. package/locales/en-US/examples.json +218 -0
  39. package/locales/en-US/form.json +11 -0
  40. package/locales/en-US/input.json +3 -0
  41. package/locales/en-US/list.json +5 -0
  42. package/locales/en-US/loading.json +3 -0
  43. package/locales/en-US/navBar.json +4 -0
  44. package/locales/en-US/noticeBar.json +3 -0
  45. package/locales/en-US/picker.json +5 -0
  46. package/locales/en-US/searchBar.json +4 -0
  47. package/locales/en-US/textarea.json +3 -0
  48. package/locales/en-US/toast.json +6 -0
  49. package/locales/index.uts +79 -0
  50. package/locales/init-verification.uts +101 -0
  51. package/locales/loader.uts +251 -0
  52. package/locales/run-verification.uts +16 -0
  53. package/locales/zh-CN/actionSheet.json +3 -0
  54. package/locales/zh-CN/common.json +10 -0
  55. package/locales/zh-CN/dialog.json +5 -0
  56. package/locales/zh-CN/empty.json +5 -0
  57. package/locales/zh-CN/errorState.json +5 -0
  58. package/locales/zh-CN/examplePages.json +1236 -0
  59. package/locales/zh-CN/examples.json +218 -0
  60. package/locales/zh-CN/form.json +11 -0
  61. package/locales/zh-CN/input.json +3 -0
  62. package/locales/zh-CN/list.json +5 -0
  63. package/locales/zh-CN/loading.json +3 -0
  64. package/locales/zh-CN/navBar.json +4 -0
  65. package/locales/zh-CN/noticeBar.json +3 -0
  66. package/locales/zh-CN/picker.json +5 -0
  67. package/locales/zh-CN/searchBar.json +4 -0
  68. package/locales/zh-CN/textarea.json +3 -0
  69. package/locales/zh-CN/toast.json +6 -0
  70. package/locales/zh-TW/actionSheet.json +3 -0
  71. package/locales/zh-TW/common.json +8 -0
  72. package/locales/zh-TW/dialog.json +5 -0
  73. package/locales/zh-TW/empty.json +5 -0
  74. package/locales/zh-TW/errorState.json +5 -0
  75. package/locales/zh-TW/examplePages.json +705 -0
  76. package/locales/zh-TW/examples.json +218 -0
  77. package/locales/zh-TW/form.json +11 -0
  78. package/locales/zh-TW/input.json +3 -0
  79. package/locales/zh-TW/list.json +5 -0
  80. package/locales/zh-TW/loading.json +3 -0
  81. package/locales/zh-TW/navBar.json +4 -0
  82. package/locales/zh-TW/noticeBar.json +3 -0
  83. package/locales/zh-TW/picker.json +5 -0
  84. package/locales/zh-TW/searchBar.json +4 -0
  85. package/locales/zh-TW/textarea.json +3 -0
  86. package/locales/zh-TW/toast.json +6 -0
  87. package/package.json +2 -1
@@ -0,0 +1,218 @@
1
+ {
2
+ "groups": {
3
+ "basic": "Basic",
4
+ "layout": "Layout",
5
+ "form": "Form",
6
+ "display": "Display",
7
+ "feedback": "Feedback",
8
+ "navigation": "Navigation",
9
+ "tools": "Tools"
10
+ },
11
+ "components": {
12
+ "TButton": {
13
+ "name": "Button",
14
+ "enName": "Button",
15
+ "description": "Trigger an action"
16
+ },
17
+ "TIcon": {
18
+ "name": "Icon",
19
+ "enName": "Icon",
20
+ "description": "Semantic icons"
21
+ },
22
+ "TText": {
23
+ "name": "Text",
24
+ "enName": "Text",
25
+ "description": "Text display component"
26
+ },
27
+ "TImage": {
28
+ "name": "Image",
29
+ "enName": "Image",
30
+ "description": "Enhanced image component"
31
+ },
32
+ "TDivider": {
33
+ "name": "Divider",
34
+ "enName": "Divider",
35
+ "description": "Content divider"
36
+ },
37
+ "TCard": {
38
+ "name": "Card",
39
+ "enName": "Card",
40
+ "description": "Card container"
41
+ },
42
+ "TList": {
43
+ "name": "List",
44
+ "enName": "List",
45
+ "description": "List display"
46
+ },
47
+ "TCell": {
48
+ "name": "Cell",
49
+ "enName": "Cell",
50
+ "description": "Cell component"
51
+ },
52
+ "TGrid": {
53
+ "name": "Grid",
54
+ "enName": "Grid",
55
+ "description": "Grid layout"
56
+ },
57
+ "TRow/TCol": {
58
+ "name": "Layout",
59
+ "enName": "Layout",
60
+ "description": "24-column grid layout"
61
+ },
62
+ "TInput": {
63
+ "name": "Input",
64
+ "enName": "Input",
65
+ "description": "Text input"
66
+ },
67
+ "TTextarea": {
68
+ "name": "Textarea",
69
+ "enName": "Textarea",
70
+ "description": "Multi-line text input"
71
+ },
72
+ "TSearchBar": {
73
+ "name": "SearchBar",
74
+ "enName": "SearchBar",
75
+ "description": "Search input box"
76
+ },
77
+ "TNumberInput": {
78
+ "name": "NumberInput",
79
+ "enName": "NumberInput",
80
+ "description": "Number input box"
81
+ },
82
+ "TSwitch": {
83
+ "name": "Switch",
84
+ "enName": "Switch",
85
+ "description": "Switch selector"
86
+ },
87
+ "TCheckbox": {
88
+ "name": "Checkbox",
89
+ "enName": "Checkbox",
90
+ "description": "Checkbox"
91
+ },
92
+ "TCheckboxGroup": {
93
+ "name": "CheckboxGroup",
94
+ "enName": "CheckboxGroup",
95
+ "description": "Checkbox group"
96
+ },
97
+ "TRadioButton": {
98
+ "name": "Radio",
99
+ "enName": "Radio",
100
+ "description": "Radio button"
101
+ },
102
+ "TRadioGroup": {
103
+ "name": "RadioGroup",
104
+ "enName": "RadioGroup",
105
+ "description": "Radio group"
106
+ },
107
+ "TSelect": {
108
+ "name": "Select",
109
+ "enName": "Select",
110
+ "description": "Dropdown selector"
111
+ },
112
+ "TPicker": {
113
+ "name": "Picker",
114
+ "enName": "Picker",
115
+ "description": "Multi-column data picker"
116
+ },
117
+ "TSlider": {
118
+ "name": "Slider",
119
+ "enName": "Slider",
120
+ "description": "Slider selector"
121
+ },
122
+ "TRate": {
123
+ "name": "Rate",
124
+ "enName": "Rate",
125
+ "description": "Rating component"
126
+ },
127
+ "TForm": {
128
+ "name": "Form",
129
+ "enName": "Form",
130
+ "description": "Form component"
131
+ },
132
+ "Tags": {
133
+ "name": "Tags",
134
+ "enName": "Tags",
135
+ "description": "Tag classification"
136
+ },
137
+ "TBadge": {
138
+ "name": "Badge",
139
+ "enName": "Badge",
140
+ "description": "Number badge"
141
+ },
142
+ "TAvatar": {
143
+ "name": "Avatar",
144
+ "enName": "Avatar",
145
+ "description": "User avatar"
146
+ },
147
+ "TProgress": {
148
+ "name": "Progress",
149
+ "enName": "Progress",
150
+ "description": "Progress indicator"
151
+ },
152
+ "TNoticeBar": {
153
+ "name": "NoticeBar",
154
+ "enName": "NoticeBar",
155
+ "description": "Scrolling notice"
156
+ },
157
+ "TCollapse": {
158
+ "name": "Collapse",
159
+ "enName": "Collapse",
160
+ "description": "Collapsible content area"
161
+ },
162
+ "TSwiper": {
163
+ "name": "Swiper",
164
+ "enName": "Swiper",
165
+ "description": "Image/content carousel"
166
+ },
167
+ "TEmpty": {
168
+ "name": "Empty",
169
+ "enName": "Empty",
170
+ "description": "Empty state display"
171
+ },
172
+ "TErrorState": {
173
+ "name": "Error",
174
+ "enName": "Error",
175
+ "description": "Error prompt"
176
+ },
177
+ "TLoading": {
178
+ "name": "Loading",
179
+ "enName": "Loading",
180
+ "description": "Loading state"
181
+ },
182
+ "TToast": {
183
+ "name": "Toast",
184
+ "enName": "Toast",
185
+ "description": "Lightweight prompt"
186
+ },
187
+ "TDialog": {
188
+ "name": "Dialog",
189
+ "enName": "Dialog",
190
+ "description": "Modal dialog"
191
+ },
192
+ "TPopup": {
193
+ "name": "Popup",
194
+ "enName": "Popup",
195
+ "description": "Popup container"
196
+ },
197
+ "TActionSheet": {
198
+ "name": "ActionSheet",
199
+ "enName": "ActionSheet",
200
+ "description": "Bottom action sheet"
201
+ },
202
+ "Tabs": {
203
+ "name": "Tabs",
204
+ "enName": "Tabs",
205
+ "description": "Tab switching"
206
+ },
207
+ "TNavBar": {
208
+ "name": "NavBar",
209
+ "enName": "NavBar",
210
+ "description": "Top navigation bar"
211
+ },
212
+ "I18nDemo": {
213
+ "name": "I18n Demo",
214
+ "enName": "I18n",
215
+ "description": "Internationalization demo"
216
+ }
217
+ }
218
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "inputPlaceholder": "Please enter {label}",
3
+ "selectPlaceholder": "Please select",
4
+ "datePlaceholder": "Select date",
5
+ "timePlaceholder": "Select time",
6
+ "requiredError": "Please enter {label}",
7
+ "submitButton": "Submit",
8
+ "resetButton": "Reset",
9
+ "validationFailed": "Form validation failed",
10
+ "submitFailed": "Form submission failed"
11
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "placeholder": "Please enter"
3
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "loadingText": "Loading...",
3
+ "finishedText": "No more data",
4
+ "errorText": "Load failed, click to retry"
5
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "text": "Loading..."
3
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "backText": "Back",
3
+ "title": "Title"
4
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "closeText": "Close"
3
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "title": "Please Select",
3
+ "confirmText": "Confirm",
4
+ "cancelText": "Cancel"
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "placeholder": "Enter search keywords",
3
+ "cancelText": "Cancel"
4
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "placeholder": "Please enter content"
3
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "loading": "Loading...",
3
+ "success": "Success",
4
+ "fail": "Failed",
5
+ "info": "Info"
6
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * 语言包初始化模块
3
+ * 负责预加载内置语言包并初始化 I18n 系统
4
+ */
5
+
6
+ import { LocaleLoader } from './loader.uts'
7
+ import { I18nManager } from '../composables/i18n/manager.uts'
8
+
9
+ /**
10
+ * 初始化标志
11
+ * 确保初始化只执行一次
12
+ */
13
+ let initialized = false
14
+
15
+ /**
16
+ * 初始化 I18n 系统(同步方法)
17
+ * 预加载内置语言包(zh-CN, en-US, zh-TW)并设置默认语言为简体中文
18
+ * 使用同步方式确保跨平台兼容性
19
+ */
20
+ export function initI18n(): void {
21
+ // 防止重复初始化
22
+ if (initialized) {
23
+ console.log('[Tang UI I18n] Already initialized, skipping...')
24
+ return
25
+ }
26
+
27
+ try {
28
+ console.log('[Tang UI I18n] Initializing i18n system...')
29
+
30
+ // 1. 预加载内置语言包(同步方法)
31
+ const localesMap = LocaleLoader.preloadBuiltinLocales()
32
+
33
+ // 2. 获取 I18nManager 单例实例
34
+ const manager = I18nManager.getInstance()
35
+
36
+ // 3. 将内置语言包注册到 I18nManager
37
+ for (const [locale, messages] of localesMap) {
38
+ manager.registerMessages(locale, messages)
39
+ console.log(`[Tang UI I18n] Registered locale: ${locale}`)
40
+ }
41
+
42
+ // 4. 设置默认语言为简体中文
43
+ const success = manager.setLocale('zh-CN')
44
+ if (success) {
45
+ console.log('[Tang UI I18n] Default locale set to zh-CN')
46
+ } else {
47
+ console.warn('[Tang UI I18n] Failed to set default locale to zh-CN')
48
+ }
49
+
50
+ // 5. 标记为已初始化
51
+ initialized = true
52
+
53
+ console.log('[Tang UI I18n] Initialization complete')
54
+ } catch (error) {
55
+ console.error('[Tang UI I18n] Failed to initialize i18n system:', error)
56
+ throw error
57
+ }
58
+ }
59
+
60
+ /**
61
+ * 检查 I18n 系统是否已初始化
62
+ * @returns 是否已初始化
63
+ */
64
+ export function isI18nInitialized(): boolean {
65
+ return initialized
66
+ }
67
+
68
+ /**
69
+ * 重置初始化状态(仅用于测试)
70
+ * @internal
71
+ */
72
+ export function resetI18nInitialization(): void {
73
+ initialized = false
74
+ }
75
+
76
+ // 自动初始化
77
+ // 在模块加载时自动初始化 i18n 系统
78
+ // 这确保了在任何组件使用 i18n 之前,系统已经准备就绪
79
+ initI18n()
@@ -0,0 +1,101 @@
1
+ /**
2
+ * 验证初始化功能
3
+ * 测试 locales/index.uts 的初始化逻辑
4
+ */
5
+
6
+ import { initI18n, isI18nInitialized, resetI18nInitialization } from './index.uts'
7
+ import { I18nManager } from '../composables/i18n/manager.uts'
8
+
9
+ /**
10
+ * 验证初始化功能(同步方法)
11
+ */
12
+ function verifyInitialization() {
13
+ console.log('=== 开始验证 I18n 初始化功能 ===\n')
14
+
15
+ // 重置初始化状态(用于测试)
16
+ resetI18nInitialization()
17
+
18
+ // 1. 验证初始化前状态
19
+ console.log('1. 验证初始化前状态')
20
+ console.log(' 已初始化:', isI18nInitialized())
21
+ console.log(' 预期: false')
22
+ console.log(' ✓ 通过\n')
23
+
24
+ // 2. 执行初始化(同步方法)
25
+ console.log('2. 执行初始化')
26
+ initI18n()
27
+ console.log(' ✓ 初始化完成\n')
28
+
29
+ // 3. 验证初始化后状态
30
+ console.log('3. 验证初始化后状态')
31
+ console.log(' 已初始化:', isI18nInitialized())
32
+ console.log(' 预期: true')
33
+ console.log(' ✓ 通过\n')
34
+
35
+ // 4. 获取 I18nManager 实例并验证
36
+ const manager = I18nManager.getInstance()
37
+
38
+ // 5. 验证默认语言
39
+ console.log('4. 验证默认语言')
40
+ const currentLocale = manager.getCurrentLocale()
41
+ console.log(' 当前语言:', currentLocale)
42
+ console.log(' 预期: zh-CN')
43
+ console.log(' 结果:', currentLocale === 'zh-CN' ? '✓ 通过' : '✗ 失败')
44
+ console.log('')
45
+
46
+ // 6. 验证可用语言列表
47
+ console.log('5. 验证可用语言列表')
48
+ const availableLocales = manager.getAvailableLocales()
49
+ const locales = availableLocales.value
50
+ console.log(' 可用语言:', locales)
51
+ console.log(' 预期包含: zh-CN, en-US, zh-TW')
52
+ const hasZhCN = locales.includes('zh-CN')
53
+ const hasEnUS = locales.includes('en-US')
54
+ const hasZhTW = locales.includes('zh-TW')
55
+ console.log(' 包含 zh-CN:', hasZhCN ? '✓' : '✗')
56
+ console.log(' 包含 en-US:', hasEnUS ? '✓' : '✗')
57
+ console.log(' 包含 zh-TW:', hasZhTW ? '✓' : '✗')
58
+ console.log(' 结果:', (hasZhCN && hasEnUS && hasZhTW) ? '✓ 通过' : '✗ 失败')
59
+ console.log('')
60
+
61
+ // 7. 验证翻译功能
62
+ console.log('6. 验证翻译功能(简体中文)')
63
+ const confirmText = manager.translate('common.confirm')
64
+ console.log(' common.confirm:', confirmText)
65
+ console.log(' 预期: 确定')
66
+ console.log(' 结果:', confirmText === '确定' ? '✓ 通过' : '✗ 失败')
67
+ console.log('')
68
+
69
+ // 8. 切换到英语并验证
70
+ console.log('7. 切换到英语并验证翻译')
71
+ const switchSuccess = manager.setLocale('en-US')
72
+ console.log(' 切换成功:', switchSuccess)
73
+ const confirmTextEn = manager.translate('common.confirm')
74
+ console.log(' common.confirm:', confirmTextEn)
75
+ console.log(' 预期: Confirm')
76
+ console.log(' 结果:', confirmTextEn === 'Confirm' ? '✓ 通过' : '✗ 失败')
77
+ console.log('')
78
+
79
+ // 9. 切换到繁体中文并验证
80
+ console.log('8. 切换到繁体中文并验证翻译')
81
+ manager.setLocale('zh-TW')
82
+ const confirmTextTw = manager.translate('common.confirm')
83
+ console.log(' common.confirm:', confirmTextTw)
84
+ console.log(' 预期: 確定')
85
+ console.log(' 结果:', confirmTextTw === '確定' ? '✓ 通过' : '✗ 失败')
86
+ console.log('')
87
+
88
+ // 10. 验证重复初始化保护
89
+ console.log('9. 验证重复初始化保护')
90
+ initI18n()
91
+ console.log(' ✓ 重复初始化被正确阻止\n')
92
+
93
+ console.log('=== 验证完成 ===')
94
+ }
95
+
96
+ // 执行验证(同步方式)
97
+ try {
98
+ verifyInitialization()
99
+ } catch (error) {
100
+ console.error('验证过程出错:', error)
101
+ }