2023-05-15 08:51:32 +08:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
import type { FC } from 'react'
|
2023-10-18 16:00:56 +08:00
|
|
|
import React, { useEffect } from 'react'
|
|
|
|
import { changeLanguage } from '@/i18n/i18next-config'
|
2023-05-15 08:51:32 +08:00
|
|
|
import I18NContext from '@/context/i18n'
|
|
|
|
import type { Locale } from '@/i18n'
|
2023-10-18 16:00:56 +08:00
|
|
|
import { setLocaleOnClient } from '@/i18n/client'
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
export type II18nProps = {
|
|
|
|
locale: Locale
|
|
|
|
dictionary: Record<string, any>
|
|
|
|
children: React.ReactNode
|
|
|
|
}
|
|
|
|
const I18n: FC<II18nProps> = ({
|
2023-10-18 16:00:56 +08:00
|
|
|
locale,
|
2023-05-15 08:51:32 +08:00
|
|
|
dictionary,
|
|
|
|
children,
|
|
|
|
}) => {
|
2023-10-18 16:00:56 +08:00
|
|
|
useEffect(() => {
|
|
|
|
changeLanguage(locale)
|
|
|
|
}, [locale])
|
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
return (
|
|
|
|
<I18NContext.Provider value={{
|
|
|
|
locale,
|
|
|
|
i18n: dictionary,
|
|
|
|
setLocaleOnClient,
|
|
|
|
}}>
|
|
|
|
{children}
|
|
|
|
</I18NContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
export default React.memo(I18n)
|