i18n.tsx 708 B

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