2023-05-15 08:51:32 +08:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
import type { FC } from 'react'
|
2025-07-23 16:04:46 +08:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2023-05-15 08:51:32 +08:00
|
|
|
import I18NContext from '@/context/i18n'
|
2025-07-25 15:01:28 +08:00
|
|
|
import type { Locale } from '@/i18n-config'
|
|
|
|
import { setLocaleOnClient } from '@/i18n-config'
|
2025-07-23 16:04:46 +08:00
|
|
|
import Loading from './base/loading'
|
|
|
|
import { usePrefetchQuery } from '@tanstack/react-query'
|
|
|
|
import { getSystemFeatures } from '@/service/common'
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
export type II18nProps = {
|
|
|
|
locale: Locale
|
|
|
|
children: React.ReactNode
|
|
|
|
}
|
|
|
|
const I18n: FC<II18nProps> = ({
|
2023-10-18 16:00:56 +08:00
|
|
|
locale,
|
2023-05-15 08:51:32 +08:00
|
|
|
children,
|
|
|
|
}) => {
|
2025-07-23 16:04:46 +08:00
|
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
|
|
|
|
usePrefetchQuery({
|
|
|
|
queryKey: ['systemFeatures'],
|
|
|
|
queryFn: getSystemFeatures,
|
|
|
|
})
|
|
|
|
|
2023-10-18 16:00:56 +08:00
|
|
|
useEffect(() => {
|
2025-07-23 16:04:46 +08:00
|
|
|
setLocaleOnClient(locale, false).then(() => {
|
|
|
|
setLoading(false)
|
|
|
|
})
|
2023-10-18 16:00:56 +08:00
|
|
|
}, [locale])
|
|
|
|
|
2025-07-23 16:04:46 +08:00
|
|
|
if (loading)
|
|
|
|
return <div className='flex h-screen w-screen items-center justify-center'><Loading type='app' /></div>
|
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
return (
|
|
|
|
<I18NContext.Provider value={{
|
|
|
|
locale,
|
2024-01-11 11:08:32 +08:00
|
|
|
i18n: {},
|
2023-05-15 08:51:32 +08:00
|
|
|
setLocaleOnClient,
|
|
|
|
}}>
|
|
|
|
{children}
|
|
|
|
</I18NContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
export default React.memo(I18n)
|