feat(config): add shared browser cookie policy
Quality / quality (ubuntu-latest) (push) Failing after 9m46s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
2026-08-12 21:53:07 +05:30
parent a0dab308f0
commit 5de792f359
15 changed files with 198 additions and 22 deletions
+12 -4
View File
@@ -30,6 +30,7 @@ export interface LocaleLoadOptions {
export interface I18nCookieConfig {
name?: string;
maxAge?: number;
domain?: string;
path?: string;
sameSite?: "Strict" | "Lax" | "None";
secure?: boolean;
@@ -253,6 +254,7 @@ export function resolveI18n(
cookie: {
name: config.cookie?.name ?? LANG_COOKIE,
maxAge: config.cookie?.maxAge ?? 31_536_000,
domain: config.cookie?.domain ?? "",
path: config.cookie?.path ?? "/",
sameSite: config.cookie?.sameSite ?? "Lax",
secure: config.cookie?.sameSite === "None" ? true : (config.cookie?.secure ?? false),
@@ -464,10 +466,16 @@ export const I18N_RUNTIME = String.raw`
var current = state();
if (current.langs && current.langs.indexOf(lang) === -1) return false;
var cookie = current.cookie || {};
var secure = cookie.secure || location.protocol === "https:";
document.cookie = encodeURIComponent(cookie.name || "${LANG_COOKIE}") + "=" + encodeURIComponent(lang) +
";path=" + (cookie.path || "/") + ";max-age=" + (cookie.maxAge || 31536000) +
";samesite=" + (cookie.sameSite || "Lax") + (secure ? ";secure" : "");
var cookieName = cookie.name || "${LANG_COOKIE}";
if (window.wrnCookies && typeof window.wrnCookies.set === "function") {
window.wrnCookies.set(cookieName, lang, "language", cookie);
} else {
var secure = cookie.secure || location.protocol === "https:";
var domain = cookie.domain ? ";domain=" + cookie.domain : "";
document.cookie = encodeURIComponent(cookieName) + "=" + encodeURIComponent(lang) +
";path=" + (cookie.path || "/") + ";max-age=" + (cookie.maxAge || 31536000) +
";samesite=" + (cookie.sameSite || "Lax") + domain + (secure ? ";secure" : "");
}
document.documentElement.lang = lang;
document.documentElement.dir = (current.directions && current.directions[lang]) || "ltr";
window.dispatchEvent(new CustomEvent("wrnexus:language-change", { detail: { locale: lang } }));