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.ts 889B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import {
  2. createContext,
  3. useContext,
  4. } from 'use-context-selector'
  5. import type { Locale } from '@/i18n'
  6. import { getDocLanguage, getLanguage, getPricingPageLanguage } from '@/i18n/language'
  7. import { noop } from 'lodash-es'
  8. type II18NContext = {
  9. locale: Locale
  10. i18n: Record<string, any>
  11. setLocaleOnClient: (_lang: Locale, _reloadPage?: boolean) => void
  12. }
  13. const I18NContext = createContext<II18NContext>({
  14. locale: 'en-US',
  15. i18n: {},
  16. setLocaleOnClient: noop,
  17. })
  18. export const useI18N = () => useContext(I18NContext)
  19. export const useGetLanguage = () => {
  20. const { locale } = useI18N()
  21. return getLanguage(locale)
  22. }
  23. export const useGetDocLanguage = () => {
  24. const { locale } = useI18N()
  25. return getDocLanguage(locale)
  26. }
  27. export const useGetPricingPageLanguage = () => {
  28. const { locale } = useI18N()
  29. return getPricingPageLanguage(locale)
  30. }
  31. export default I18NContext