2023-05-15 08:51:32 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-08-23 13:54:40 +08:00
|
|
|
export const setLocaleOnClient = (locale: Locale, reloadPage = true) => {
|
2023-05-15 08:51:32 +08:00
|
|
|
Cookies.set(LOCALE_COOKIE_NAME, locale)
|
|
|
|
changeLanguage(locale)
|
2023-08-23 13:54:40 +08:00
|
|
|
reloadPage && location.reload()
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|