You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

i18n.tsx 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useEffect, useState } from 'react'
  4. import I18NContext from '@/context/i18n'
  5. import type { Locale } from '@/i18n'
  6. import { setLocaleOnClient } from '@/i18n'
  7. import Loading from './base/loading'
  8. import { usePrefetchQuery } from '@tanstack/react-query'
  9. import { getSystemFeatures } from '@/service/common'
  10. export type II18nProps = {
  11. locale: Locale
  12. children: React.ReactNode
  13. }
  14. const I18n: FC<II18nProps> = ({
  15. locale,
  16. children,
  17. }) => {
  18. const [loading, setLoading] = useState(true)
  19. usePrefetchQuery({
  20. queryKey: ['systemFeatures'],
  21. queryFn: getSystemFeatures,
  22. })
  23. useEffect(() => {
  24. setLocaleOnClient(locale, false).then(() => {
  25. setLoading(false)
  26. })
  27. }, [locale])
  28. if (loading)
  29. return <div className='flex h-screen w-screen items-center justify-center'><Loading type='app' /></div>
  30. return (
  31. <I18NContext.Provider value={{
  32. locale,
  33. i18n: {},
  34. setLocaleOnClient,
  35. }}>
  36. {children}
  37. </I18NContext.Provider>
  38. )
  39. }
  40. export default React.memo(I18n)