i18n.tsx 610 B

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