Skip to content

Commit 68abe76

Browse files
luxiaobeiminlovehua
authored andcommitted
feat(components): use window language #TINFR-1711
1 parent 1b4392d commit 68abe76

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

packages/components/i18n/i18n.service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,30 @@ export class ThyI18nService {
1919
[ThyI18nLocale.ruRu]: ruRuLocale.translations
2020
};
2121

22-
private defaultLocale: ThyI18nLocale = inject(THY_I18N_DEFAULT_LOCALE_TOKEN, { optional: true }) || ThyI18nLocale.zhCn;
22+
private defaultLocale: ThyI18nLocale = inject(THY_I18N_DEFAULT_LOCALE_TOKEN, { optional: true }) || this.getDefaultLocaleId();
2323

2424
private locale: WritableSignal<ThyI18nTranslation> = signal(this.locales[this.defaultLocale]);
2525

2626
private normalizeLocale(id: string) {
2727
return (id?.toLowerCase() as ThyI18nLocale) ?? ThyI18nLocale.zhCn;
2828
}
2929

30+
private getDefaultLocaleId(): ThyI18nLocale {
31+
let defaultLocaleId = ThyI18nLocale.zhCn;
32+
const allLocales = [
33+
ThyI18nLocale.zhCn,
34+
ThyI18nLocale.zhTw,
35+
ThyI18nLocale.enUs,
36+
ThyI18nLocale.jaJp,
37+
ThyI18nLocale.deDe,
38+
ThyI18nLocale.ruRu
39+
];
40+
if (typeof window !== 'undefined' && window?.navigator?.language) {
41+
defaultLocaleId = window.navigator?.language?.toLowerCase() as ThyI18nLocale;
42+
}
43+
return allLocales.includes(this.normalizeLocale(defaultLocaleId) as ThyI18nLocale) ? defaultLocaleId : ThyI18nLocale.zhCn;
44+
}
45+
3046
/**
3147
* 设置语言
3248
* @param id

packages/components/i18n/locales/en-us.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export const enUsLocale: ThyI18nLocaleConfig = {
88
count: '',
99
forbidDropInEntry: 'Cannot reach this entry',
1010
expandedAll: 'Expand all',
11-
foldUpAll: 'Fold up all',
11+
foldUpAll: 'Collapse all',
1212
lane: 'Lane',
13-
wipLimitStatistics: 'Total {{count}} pcs / WIP limit {{wipLimit}} pcs',
14-
countStatistics: 'Total {{count}} pcs',
15-
foldUp: 'Fold up',
13+
wipLimitStatistics: 'Total {{count}} / WIP limit {{wipLimit}}',
14+
countStatistics: 'Total {{count}}',
15+
foldUp: 'Collapse',
1616
expand: 'Expand',
1717
emptyGroup: 'Ungrouped',
1818

@@ -34,9 +34,9 @@ export const enUsLocale: ThyI18nLocaleConfig = {
3434
setting: 'Settings',
3535
secondaryTitle: 'Secondary title',
3636

37-
speed: 'speed',
38-
audioFormatError: 'This audio is not supported for preview. Please upgrade your browser version or download to view.',
37+
speed: 'Speed',
38+
audioFormatError: 'This audio is not currently supported for preview, upgrade your browser version or download to view.',
3939
networkError: 'The current network is abnormal. Please refresh and try again.',
40-
videoFormatError: 'This video is not supported for preview. Please upgrade your browser version or download to view.'
40+
videoFormatError: 'This video is not currently supported for preview, upgrade your browser version or download to view.'
4141
}
4242
};

0 commit comments

Comments
 (0)