rayyy-vue-table-components 2.0.19 → 2.0.21
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.
- package/dist/index.es.js +1819 -1813
- package/dist/index.umd.js +6 -6
- package/dist/src/utils/i18n.d.ts +0 -11
- package/package.json +1 -1
- package/src/utils/i18n.ts +33 -73
package/dist/src/utils/i18n.d.ts
CHANGED
|
@@ -3,17 +3,6 @@ import { I18n, Composer } from 'vue-i18n';
|
|
|
3
3
|
* 設定內部 i18n 的語系
|
|
4
4
|
*/
|
|
5
5
|
export declare function setLocale(locale: string): void;
|
|
6
|
-
/**
|
|
7
|
-
* 組件內使用的 i18n composable
|
|
8
|
-
* 會優先使用外部專案的 i18n,如果不存在則使用內部 i18n
|
|
9
|
-
*/
|
|
10
|
-
export declare function useComponentI18n(): {
|
|
11
|
-
t: import('vue-i18n').ComposerTranslation<{}, string, import('@intlify/core-base').RemoveIndexSignature<{
|
|
12
|
-
[x: string]: import('vue-i18n').LocaleMessageValue<import('vue-i18n').VueMessageType>;
|
|
13
|
-
}>, never, never, never>;
|
|
14
|
-
locale: import('vue').WritableComputedRef<string, string>;
|
|
15
|
-
i18n: Composer<{}, {}, {}, string, never, string>;
|
|
16
|
-
};
|
|
17
6
|
/**
|
|
18
7
|
* 全域 i18n 實例(用於非組件環境)
|
|
19
8
|
*/
|
package/package.json
CHANGED
package/src/utils/i18n.ts
CHANGED
|
@@ -37,61 +37,6 @@ export function setLocale(locale: string): void {
|
|
|
37
37
|
global.locale.value = locale
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/**
|
|
41
|
-
* 組件內使用的 i18n composable
|
|
42
|
-
* 會優先使用外部專案的 i18n,如果不存在則使用內部 i18n
|
|
43
|
-
*/
|
|
44
|
-
export function useComponentI18n() {
|
|
45
|
-
console.log('🔍 [useComponentI18n] 開始執行')
|
|
46
|
-
|
|
47
|
-
const instance = getCurrentInstance()
|
|
48
|
-
console.log('🔍 [useComponentI18n] 獲取 instance:', !!instance)
|
|
49
|
-
|
|
50
|
-
// 嘗試取得外部專案的 i18n(支援 Composition API 模式)
|
|
51
|
-
let externalI18n: Composer | undefined
|
|
52
|
-
try {
|
|
53
|
-
console.log('🔍 [useComponentI18n] 嘗試獲取外部 i18n')
|
|
54
|
-
const globalProperties = instance?.appContext.config.globalProperties
|
|
55
|
-
console.log('🔍 [useComponentI18n] globalProperties:', !!globalProperties)
|
|
56
|
-
|
|
57
|
-
const externalI18nInstance = globalProperties?.$i18n as I18n | undefined
|
|
58
|
-
console.log('🔍 [useComponentI18n] externalI18nInstance:', !!externalI18nInstance)
|
|
59
|
-
|
|
60
|
-
// 如果是 I18n 實例,取得其 global 屬性
|
|
61
|
-
if (externalI18nInstance && 'global' in externalI18nInstance) {
|
|
62
|
-
externalI18n = externalI18nInstance.global as Composer
|
|
63
|
-
console.log('🔍 [useComponentI18n] 成功獲取外部 i18n,locale:', externalI18n.locale.value)
|
|
64
|
-
} else {
|
|
65
|
-
console.log('🔍 [useComponentI18n] 外部 i18n 實例不存在或格式不正確')
|
|
66
|
-
}
|
|
67
|
-
} catch (e) {
|
|
68
|
-
console.log('❌ [useComponentI18n] 獲取外部 i18n 失敗:', e)
|
|
69
|
-
// 如果取得失敗,繼續使用內部 i18n
|
|
70
|
-
externalI18n = undefined
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// 取得內部 i18n
|
|
74
|
-
console.log('🔍 [useComponentI18n] 獲取內部 i18n')
|
|
75
|
-
const internalI18nInstance = getInternalI18n()
|
|
76
|
-
const internalGlobal = internalI18nInstance.global as Composer
|
|
77
|
-
console.log('🔍 [useComponentI18n] 內部 i18n locale:', internalGlobal.locale.value)
|
|
78
|
-
|
|
79
|
-
// 如果存在外部 i18n,優先使用外部的(因為外部可能有覆蓋的翻譯)
|
|
80
|
-
// 但要支援回退到內部 i18n
|
|
81
|
-
const currentI18n = externalI18n || internalGlobal
|
|
82
|
-
console.log('🔍 [useComponentI18n] 最終使用 i18n:', externalI18n ? '外部' : '內部', 'locale:', currentI18n.locale.value)
|
|
83
|
-
|
|
84
|
-
// 直接使用 i18n 的 t 函數(它本身就是響應式的)
|
|
85
|
-
// 如果需要回退邏輯,我們需要檢查 key 是否存在
|
|
86
|
-
const t = currentI18n.t
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
t,
|
|
90
|
-
locale: currentI18n.locale,
|
|
91
|
-
i18n: currentI18n,
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
40
|
/**
|
|
96
41
|
* 全域 i18n 實例(用於非組件環境)
|
|
97
42
|
*/
|
|
@@ -110,25 +55,40 @@ export function useI18n() {
|
|
|
110
55
|
export function useComponentElementLocale() {
|
|
111
56
|
console.log('🔍 [useComponentElementLocale] 開始執行')
|
|
112
57
|
|
|
113
|
-
|
|
114
|
-
console.log('🔍 [useComponentElementLocale]
|
|
115
|
-
|
|
116
|
-
|
|
58
|
+
return computed(() => {
|
|
59
|
+
console.log('🔍 [useComponentElementLocale] computed 開始執行')
|
|
60
|
+
|
|
61
|
+
// 在 computed 內部嘗試獲取外部 i18n(確保響應式)
|
|
62
|
+
const instance = getCurrentInstance()
|
|
63
|
+
let externalLocale: any = undefined
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
console.log('🔍 [useComponentElementLocale] 嘗試獲取外部 i18n')
|
|
67
|
+
const globalProperties = instance?.appContext.config.globalProperties
|
|
68
|
+
const externalI18nInstance = globalProperties?.$i18n as I18n | undefined
|
|
69
|
+
|
|
70
|
+
if (externalI18nInstance && 'global' in externalI18nInstance) {
|
|
71
|
+
externalLocale = externalI18nInstance.global.locale
|
|
72
|
+
console.log('🔍 [useComponentElementLocale] 成功獲取外部 locale:', externalLocale.value)
|
|
73
|
+
} else {
|
|
74
|
+
console.log('🔍 [useComponentElementLocale] 外部 i18n 不存在')
|
|
75
|
+
}
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.log('❌ [useComponentElementLocale] 獲取外部 i18n 失敗:', e)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 獲取內部 i18n(回退)
|
|
81
|
+
const { locale: internalLocale } = useI18n()
|
|
82
|
+
console.log('🔍 [useComponentElementLocale] 內部 locale:', internalLocale.value)
|
|
117
83
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// 防呆:預設中文
|
|
127
|
-
return computed(() => {
|
|
128
|
-
console.log('🔍 [useComponentElementLocale] 使用預設中文')
|
|
129
|
-
return zhTw
|
|
130
|
-
})
|
|
131
|
-
}
|
|
84
|
+
// 決定使用哪個 locale
|
|
85
|
+
const currentLocale = externalLocale || internalLocale
|
|
86
|
+
console.log('🔍 [useComponentElementLocale] 最終使用 locale:', currentLocale.value)
|
|
87
|
+
|
|
88
|
+
const result = currentLocale.value === 'zh-TW' ? zhTw : enUs
|
|
89
|
+
console.log('🔍 [useComponentElementLocale] 返回結果:', result.name)
|
|
90
|
+
return result
|
|
91
|
+
})
|
|
132
92
|
}
|
|
133
93
|
|
|
134
94
|
// 導出類型
|