i18n.tsx 655 B

1234567891011121314151617181920212223242526272829303132
  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'
  8. export type II18nProps = {
  9. locale: Locale
  10. children: React.ReactNode
  11. }
  12. const I18n: FC<II18nProps> = ({
  13. locale,
  14. children,
  15. }) => {
  16. useEffect(() => {
  17. changeLanguage(locale)
  18. }, [locale])
  19. return (
  20. <I18NContext.Provider value={{
  21. locale,
  22. i18n: {},
  23. setLocaleOnClient,
  24. }}>
  25. {children}
  26. </I18NContext.Provider>
  27. )
  28. }
  29. export default React.memo(I18n)