@kuankuan/assist-2026 0.1.4 → 0.1.6
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/i18n.d.ts +3 -1
- package/dist/i18n.js +15 -3
- package/package.json +1 -1
- package/src/i18n.ts +12 -4
package/dist/i18n.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { type Ref } from 'vue';
|
|
|
3
3
|
export default class I18nInstance {
|
|
4
4
|
readonly messages: unknown;
|
|
5
5
|
readonly langs: string[];
|
|
6
|
+
private readonly storageKey;
|
|
7
|
+
readonly languageNameMap: Record<string, string>;
|
|
6
8
|
private readonly localSettingLanguage;
|
|
7
9
|
private readonly browserLanguage;
|
|
8
10
|
readonly languageList: {
|
|
@@ -11,7 +13,7 @@ export default class I18nInstance {
|
|
|
11
13
|
}[];
|
|
12
14
|
readonly language: Ref<string>;
|
|
13
15
|
readonly i18n: I18n<any, Record<string, unknown>, Record<string, unknown>, string, false>;
|
|
14
|
-
constructor(messages: unknown, langs: string[], storageKey?: string);
|
|
16
|
+
constructor(messages: unknown, langs: string[], storageKey?: string, languageNameMap?: Record<string, string>);
|
|
15
17
|
t(key: string): string;
|
|
16
18
|
tRef(key: string): import("vue").ComputedRef<string>;
|
|
17
19
|
languageName(lan: string): Ref<string, string> | import("vue").ComputedRef<string>;
|
package/dist/i18n.js
CHANGED
|
@@ -21,25 +21,34 @@ function getBrowserLanguageInLangs(langs) {
|
|
|
21
21
|
}
|
|
22
22
|
return langs[0] || 'en-us';
|
|
23
23
|
}
|
|
24
|
+
const languageNameMapPreset = {
|
|
25
|
+
'zh-tw': '繁体中文',
|
|
26
|
+
'zh-cn': '简体中文',
|
|
27
|
+
'en-us': 'English',
|
|
28
|
+
};
|
|
24
29
|
export default class I18nInstance {
|
|
25
30
|
messages;
|
|
26
31
|
langs;
|
|
32
|
+
storageKey;
|
|
33
|
+
languageNameMap;
|
|
27
34
|
localSettingLanguage;
|
|
28
35
|
browserLanguage;
|
|
29
36
|
languageList;
|
|
30
37
|
language;
|
|
31
38
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
39
|
i18n;
|
|
33
|
-
constructor(messages, langs, storageKey = '_vue_i18n_main_locale') {
|
|
40
|
+
constructor(messages, langs, storageKey = '_vue_i18n_main_locale', languageNameMap = languageNameMapPreset) {
|
|
34
41
|
this.messages = messages;
|
|
35
42
|
this.langs = langs;
|
|
43
|
+
this.storageKey = storageKey;
|
|
44
|
+
this.languageNameMap = languageNameMap;
|
|
36
45
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
37
46
|
const now = this;
|
|
38
47
|
this.languageList = ['_auto', ...langs].map((i) => ({
|
|
39
48
|
id: i,
|
|
40
49
|
name: this.languageName(i),
|
|
41
50
|
}));
|
|
42
|
-
this.localSettingLanguage = storageRef(storageKey, '_auto');
|
|
51
|
+
this.localSettingLanguage = storageRef(this.storageKey, '_auto');
|
|
43
52
|
this.browserLanguage = computed(() => getBrowserLanguageInLangs(browserLanguageSetting.value));
|
|
44
53
|
watch(() => now.localSettingLanguage.value, (newValue) => {
|
|
45
54
|
if (newValue !== '_auto' && !now.langs.includes(newValue)) {
|
|
@@ -76,7 +85,10 @@ export default class I18nInstance {
|
|
|
76
85
|
}
|
|
77
86
|
languageName(lan) {
|
|
78
87
|
if (lan === '_auto') {
|
|
79
|
-
return computed(() => `Auto-${this.languageName(this.browserLanguage.value)}`);
|
|
88
|
+
return computed(() => `Auto-${this.languageName(this.browserLanguage.value).value}`);
|
|
89
|
+
}
|
|
90
|
+
if (lan in this.languageNameMap) {
|
|
91
|
+
return ref(this.languageNameMap[lan]);
|
|
80
92
|
}
|
|
81
93
|
return ref(new Intl.DisplayNames([lan], { type: 'language' }).of(lan) || lan);
|
|
82
94
|
}
|
package/package.json
CHANGED
package/src/i18n.ts
CHANGED
|
@@ -24,7 +24,11 @@ function getBrowserLanguageInLangs(langs: string[]) {
|
|
|
24
24
|
}
|
|
25
25
|
return langs[0] || 'en-us';
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
const languageNameMapPreset = {
|
|
28
|
+
'zh-tw': '繁体中文',
|
|
29
|
+
'zh-cn': '简体中文',
|
|
30
|
+
'en-us': 'English',
|
|
31
|
+
};
|
|
28
32
|
export default class I18nInstance {
|
|
29
33
|
private readonly localSettingLanguage: Ref<string>;
|
|
30
34
|
private readonly browserLanguage: Ref<string>;
|
|
@@ -37,7 +41,8 @@ export default class I18nInstance {
|
|
|
37
41
|
constructor(
|
|
38
42
|
public readonly messages: unknown,
|
|
39
43
|
public readonly langs: string[],
|
|
40
|
-
storageKey: string = '_vue_i18n_main_locale'
|
|
44
|
+
private readonly storageKey: string = '_vue_i18n_main_locale',
|
|
45
|
+
public readonly languageNameMap: Record<string, string> = languageNameMapPreset
|
|
41
46
|
) {
|
|
42
47
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
43
48
|
const now = this;
|
|
@@ -45,7 +50,7 @@ export default class I18nInstance {
|
|
|
45
50
|
id: i,
|
|
46
51
|
name: this.languageName(i),
|
|
47
52
|
}));
|
|
48
|
-
this.localSettingLanguage = storageRef(storageKey, '_auto');
|
|
53
|
+
this.localSettingLanguage = storageRef(this.storageKey, '_auto');
|
|
49
54
|
this.browserLanguage = computed(() => getBrowserLanguageInLangs(browserLanguageSetting.value));
|
|
50
55
|
watch(
|
|
51
56
|
() => now.localSettingLanguage.value,
|
|
@@ -88,7 +93,10 @@ export default class I18nInstance {
|
|
|
88
93
|
}
|
|
89
94
|
languageName(lan: string) {
|
|
90
95
|
if (lan === '_auto') {
|
|
91
|
-
return computed((): string => `Auto-${this.languageName(this.browserLanguage.value)}`);
|
|
96
|
+
return computed((): string => `Auto-${this.languageName(this.browserLanguage.value).value}`);
|
|
97
|
+
}
|
|
98
|
+
if (lan in this.languageNameMap) {
|
|
99
|
+
return ref(this.languageNameMap[lan]);
|
|
92
100
|
}
|
|
93
101
|
return ref(new Intl.DisplayNames([lan], { type: 'language' }).of(lan) || lan);
|
|
94
102
|
}
|