diff --git a/web/i18n-config/action.ts b/web/i18n-config/action.ts new file mode 100644 index 0000000000..27f7ecc406 --- /dev/null +++ b/web/i18n-config/action.ts @@ -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, + }, + ) +} diff --git a/web/i18n-config/index.ts b/web/i18n-config/index.ts index bb73ef4b71..ecc12643a8 100644 --- a/web/i18n-config/index.ts +++ b/web/i18n-config/index.ts @@ -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 => {