mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
17 lines
484 B
TypeScript
17 lines
484 B
TypeScript
|
import Cookies from 'js-cookie'
|
||
|
import type { Locale } from '.'
|
||
|
import { i18n } from '.'
|
||
|
import { LOCALE_COOKIE_NAME } from '@/config'
|
||
|
import { changeLanguage } from '@/i18n/i18next-config'
|
||
|
|
||
|
// same logic as server
|
||
|
export const getLocaleOnClient = (): Locale => {
|
||
|
return Cookies.get(LOCALE_COOKIE_NAME) as Locale || i18n.defaultLocale
|
||
|
}
|
||
|
|
||
|
export const setLocaleOnClient = (locale: Locale) => {
|
||
|
Cookies.set(LOCALE_COOKIE_NAME, locale)
|
||
|
changeLanguage(locale)
|
||
|
location.reload()
|
||
|
}
|