i18n.ts 627 B

123456789101112131415161718192021222324252627
  1. import {
  2. createContext,
  3. useContext,
  4. } from 'use-context-selector'
  5. import type { Locale } from '@/i18n'
  6. import { getLanguage } from '@/i18n/language'
  7. type II18NContext = {
  8. locale: Locale
  9. i18n: Record<string, any>
  10. setLocaleOnClient: (_lang: Locale, _reloadPage?: boolean) => void
  11. }
  12. const I18NContext = createContext<II18NContext>({
  13. locale: 'en-US',
  14. i18n: {},
  15. setLocaleOnClient: (_lang: Locale, _reloadPage?: boolean) => { },
  16. })
  17. export const useI18N = () => useContext(I18NContext)
  18. export const useGetLanguage = () => {
  19. const { locale } = useI18N()
  20. return getLanguage(locale)
  21. }
  22. export default I18NContext