dify/web/context/i18n.ts

28 lines
627 B
TypeScript
Raw Permalink Normal View History

import {
createContext,
useContext,
} from 'use-context-selector'
2023-05-15 08:51:32 +08:00
import type { Locale } from '@/i18n'
import { getLanguage } from '@/i18n/language'
2023-05-15 08:51:32 +08:00
type II18NContext = {
locale: Locale
i18n: Record<string, any>
setLocaleOnClient: (_lang: Locale, _reloadPage?: boolean) => void
2023-05-15 08:51:32 +08:00
}
const I18NContext = createContext<II18NContext>({
2024-02-23 14:31:06 +08:00
locale: 'en-US',
2023-05-15 08:51:32 +08:00
i18n: {},
setLocaleOnClient: (_lang: Locale, _reloadPage?: boolean) => { },
2023-05-15 08:51:32 +08:00
})
export const useI18N = () => useContext(I18NContext)
export const useGetLanguage = () => {
const { locale } = useI18N()
return getLanguage(locale)
}
2023-05-15 08:51:32 +08:00
export default I18NContext