mirror of https://github.com/langgenius/dify.git
cookie from server
This commit is contained in:
parent
02b68f5a30
commit
442fef4bee
|
|
@ -0,0 +1,16 @@
|
|||
'use server'
|
||||
|
||||
import type { Locale } from './language'
|
||||
import { cookies } from 'next/headers'
|
||||
import { LOCALE_COOKIE_NAME } from '@/config'
|
||||
|
||||
export async function setUserLocaleServer(locale: Locale) {
|
||||
(await cookies()).set(
|
||||
LOCALE_COOKIE_NAME,
|
||||
locale,
|
||||
{
|
||||
// A year in milliseconds
|
||||
expires: 60 * 60 * 24 * 365 * 1000,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import Cookies from 'js-cookie'
|
|||
import { LOCALE_COOKIE_NAME } from '@/config'
|
||||
import { changeLanguage } from '@/i18n-config/i18next-config'
|
||||
import { LanguagesSupported } from '@/i18n-config/language'
|
||||
import { setUserLocaleServer } from './action'
|
||||
|
||||
export const i18n = {
|
||||
defaultLocale: 'en-US',
|
||||
|
|
@ -13,10 +14,9 @@ export const i18n = {
|
|||
export { Locale }
|
||||
|
||||
export const setLocaleOnClient = async (locale: Locale, reloadPage = true) => {
|
||||
Cookies.set(LOCALE_COOKIE_NAME, locale, { expires: 365 })
|
||||
await changeLanguage(locale)
|
||||
if (reloadPage)
|
||||
location.reload()
|
||||
await setUserLocaleServer(locale)
|
||||
}
|
||||
|
||||
export const getLocaleOnClient = (): Locale => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue