@@ -12,8 +12,9 @@ import i18n from 'i18next';
1212import { initReactI18next } from 'react-i18next' ;
1313import { en } from './en' ;
1414import { zhCN } from './zh-CN' ;
15+ import { zhTW } from './zh-TW' ;
1516
16- export const SUPPORTED_LOCALES = [ 'zh-CN' , 'en' ] as const ;
17+ export const SUPPORTED_LOCALES = [ 'zh-CN' , 'zh-TW' , ' en'] as const ;
1718export type SupportedLocale = ( typeof SUPPORTED_LOCALES ) [ number ] ;
1819
1920export const LOCALE_STORAGE_KEY = 'ol.locale' ;
@@ -22,21 +23,25 @@ const FOLLOW_SYSTEM_VALUE = 'system';
2223function detectSystemLocale ( ) : SupportedLocale {
2324 if ( typeof navigator === 'undefined' ) return 'zh-CN' ;
2425 const nav = ( navigator . language || '' ) . toLowerCase ( ) ;
25- if ( nav . startsWith ( 'zh' ) ) return 'zh-CN' ;
26+ if ( nav . startsWith ( 'zh' ) ) {
27+ if ( nav . includes ( 'hant' ) || nav . includes ( 'tw' ) || nav . includes ( 'hk' ) || nav . includes ( 'mo' ) ) return 'zh-TW' ;
28+ return 'zh-CN' ;
29+ }
2630 return 'en' ;
2731}
2832
2933function getStoredLocale ( ) : SupportedLocale | null {
3034 if ( typeof window === 'undefined' ) return null ;
3135 const raw = window . localStorage . getItem ( LOCALE_STORAGE_KEY ) ;
32- return raw === 'zh-CN' || raw === 'en' ? raw : null ;
36+ return raw === 'zh-CN' || raw === 'zh-TW' || raw === ' en' ? raw : null ;
3337}
3438
3539const initialLng : SupportedLocale = getStoredLocale ( ) ?? detectSystemLocale ( ) ;
3640
3741void i18n . use ( initReactI18next ) . init ( {
3842 resources : {
3943 'zh-CN' : { translation : zhCN } ,
44+ 'zh-TW' : { translation : zhTW } ,
4045 en : { translation : en } ,
4146 } ,
4247 lng : initialLng ,
0 commit comments