forked from tuvn86/webapp-conversation
feat: init
This commit is contained in:
parent
8acd8f6fbd
commit
97d3a6277d
77 changed files with 5299 additions and 0 deletions
18
i18n/client.ts
Normal file
18
i18n/client.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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, notReload?: boolean) => {
|
||||
Cookies.set(LOCALE_COOKIE_NAME, locale)
|
||||
changeLanguage(locale)
|
||||
if (!notReload) {
|
||||
location.reload()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue