mirror of
https://github.com/langgenius/dify.git
synced 2026-08-28 21:23:22 +08:00
cookie from server
This commit is contained in:
parent
02b68f5a30
commit
442fef4bee
16
web/i18n-config/action.ts
Normal file
16
web/i18n-config/action.ts
Normal file
@ -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 { LOCALE_COOKIE_NAME } from '@/config'
|
||||||
import { changeLanguage } from '@/i18n-config/i18next-config'
|
import { changeLanguage } from '@/i18n-config/i18next-config'
|
||||||
import { LanguagesSupported } from '@/i18n-config/language'
|
import { LanguagesSupported } from '@/i18n-config/language'
|
||||||
|
import { setUserLocaleServer } from './action'
|
||||||
|
|
||||||
export const i18n = {
|
export const i18n = {
|
||||||
defaultLocale: 'en-US',
|
defaultLocale: 'en-US',
|
||||||
@ -13,10 +14,9 @@ export const i18n = {
|
|||||||
export { Locale }
|
export { Locale }
|
||||||
|
|
||||||
export const setLocaleOnClient = async (locale: Locale, reloadPage = true) => {
|
export const setLocaleOnClient = async (locale: Locale, reloadPage = true) => {
|
||||||
Cookies.set(LOCALE_COOKIE_NAME, locale, { expires: 365 })
|
|
||||||
await changeLanguage(locale)
|
await changeLanguage(locale)
|
||||||
if (reloadPage)
|
if (reloadPage)
|
||||||
location.reload()
|
await setUserLocaleServer(locale)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getLocaleOnClient = (): Locale => {
|
export const getLocaleOnClient = (): Locale => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user