i18n.tsx 718 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useEffect } from 'react'
  4. import { changeLanguage } from '@/i18n/i18next-config'
  5. import I18NContext from '@/context/i18n'
  6. import type { Locale } from '@/i18n'
  7. import { setLocaleOnClient } from '@/i18n/client'
  8. export type II18nProps = {
  9. locale: Locale
  10. dictionary: Record<string, any>
  11. children: React.ReactNode
  12. }
  13. const I18n: FC<II18nProps> = ({
  14. locale,
  15. dictionary,
  16. children,
  17. }) => {
  18. useEffect(() => {
  19. changeLanguage(locale)
  20. }, [locale])
  21. return (
  22. <I18NContext.Provider value={{
  23. locale,
  24. i18n: dictionary,
  25. setLocaleOnClient,
  26. }}>
  27. {children}
  28. </I18NContext.Provider>
  29. )
  30. }
  31. export default React.memo(I18n)