mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
23 lines
634 B
TypeScript
23 lines
634 B
TypeScript
import Cookies from 'js-cookie'
|
|
|
|
import { changeLanguage } from '@/i18n/i18next-config'
|
|
import { LOCALE_COOKIE_NAME } from '@/config'
|
|
import { LanguagesSupported } from '@/i18n/language'
|
|
|
|
export const i18n = {
|
|
defaultLocale: 'en-US',
|
|
locales: LanguagesSupported,
|
|
} as const
|
|
|
|
export type Locale = typeof i18n['locales'][number]
|
|
|
|
export const getLocaleOnClient = (): Locale => {
|
|
return Cookies.get(LOCALE_COOKIE_NAME) as Locale || i18n.defaultLocale
|
|
}
|
|
|
|
export const setLocaleOnClient = (locale: Locale, reloadPage = true) => {
|
|
Cookies.set(LOCALE_COOKIE_NAME, locale)
|
|
changeLanguage(locale)
|
|
reloadPage && location.reload()
|
|
}
|