@zachhandley/ez-i18n 0.3.16 → 0.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +4 -1
- package/package.json +1 -1
package/dist/runtime/index.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ declare function setLocale(locale: string, options?: string | {
|
|
|
51
51
|
cookieName?: string;
|
|
52
52
|
loadTranslations?: TranslationLoader;
|
|
53
53
|
redirect?: boolean;
|
|
54
|
+
/** Async callback to run before redirect (e.g., save preferences to backend) */
|
|
55
|
+
beforeRedirect?: (locale: string) => Promise<void>;
|
|
54
56
|
}): Promise<void>;
|
|
55
57
|
/**
|
|
56
58
|
* Get current locale value (non-reactive)
|
package/dist/runtime/index.js
CHANGED
|
@@ -41,8 +41,11 @@ function setTranslations(trans) {
|
|
|
41
41
|
}
|
|
42
42
|
async function setLocale(locale, options = {}) {
|
|
43
43
|
const opts = typeof options === "string" ? { cookieName: options } : options;
|
|
44
|
-
const { cookieName = "ez-locale", loadTranslations, redirect } = opts;
|
|
44
|
+
const { cookieName = "ez-locale", loadTranslations, redirect, beforeRedirect } = opts;
|
|
45
45
|
if (redirect && typeof window !== "undefined") {
|
|
46
|
+
if (beforeRedirect) {
|
|
47
|
+
await beforeRedirect(locale);
|
|
48
|
+
}
|
|
46
49
|
const url = new URL(window.location.href);
|
|
47
50
|
url.searchParams.set("lang", locale);
|
|
48
51
|
window.location.href = url.toString();
|