@@ -9,9 +9,23 @@ import { ConfigProvider as AConfigProvider, type GetProps, theme } from 'antd';
99import type { Locale } from 'antd/es/locale' ;
1010import dayjs from 'dayjs' ;
1111import { produce } from 'immer' ;
12+ import { getLocaleFromNavigator } from 'svelte-i18n' ;
1213
1314import { getDefaultLocale , locales } from './locales' ;
1415
16+ function formatLocale ( locale : string | null ) {
17+ if ( ! locale ) {
18+ return 'en_US' ;
19+ }
20+
21+ const parts = locale . replace ( '-' , '_' ) . split ( '_' ) ;
22+
23+ if ( parts . length === 2 ) {
24+ return `${ parts [ 0 ] . toLowerCase ( ) } _${ parts [ 1 ] . toUpperCase ( ) } ` ;
25+ }
26+ return 'en_US' ;
27+ }
28+
1529const combinePropsAndSlots = (
1630 props : Record < string , any > ,
1731 slots : Record < string , HTMLElement >
@@ -61,7 +75,7 @@ export const ConfigProvider = sveltify<
6175 id,
6276 className,
6377 style,
64- locale : localeProp = 'en_US' ,
78+ locale : localeProp = formatLocale ( getLocaleFromNavigator ( ) ) ,
6579 getTargetContainer,
6680 getPopupContainer,
6781 renderEmpty,
@@ -82,14 +96,14 @@ export const ConfigProvider = sveltify<
8296 const getTargetContainerFunction = useFunction ( getTargetContainer ) ;
8397 const renderEmptyFunction = useFunction ( renderEmpty ) ;
8498 useEffect ( ( ) => {
85- if ( localeProp && locales [ localeProp ] ) {
86- locales [ localeProp ] ( ) . then (
87- ( { antd : antdLocale , dayjs : dayjsLocale } ) => {
88- setLocale ( antdLocale ) ;
89- dayjs . locale ( dayjsLocale ) ;
90- }
91- ) ;
92- }
99+ const getLocaleConfig =
100+ localeProp && locales [ localeProp ]
101+ ? locales [ localeProp ]
102+ : locales [ 'en_US' ] ;
103+ getLocaleConfig ( ) . then ( ( { antd : antdLocale , dayjs : dayjsLocale } ) => {
104+ setLocale ( antdLocale ) ;
105+ dayjs . locale ( dayjsLocale ) ;
106+ } ) ;
93107 } , [ localeProp ] ) ;
94108 const ProviderComponent = component || AConfigProvider ;
95109 return (
0 commit comments