@7365admin1/layer-common 4.97.1-staging.731 → 4.97.1-staging.732
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.
|
@@ -33,16 +33,22 @@ function applyHtmlLang(code: string) {
|
|
|
33
33
|
export function installUiLanguage(deps: {
|
|
34
34
|
post: (q: string[], target: string) => Promise<any>;
|
|
35
35
|
getVersion: () => Promise<any>;
|
|
36
|
+
/** The shared-domain cookie, so the choice follows the user across the apps. */
|
|
37
|
+
sharedLanguage?: () => string | undefined;
|
|
38
|
+
shareLanguage?: (code: string) => void;
|
|
36
39
|
}) {
|
|
37
40
|
if (engine || typeof window === "undefined") return;
|
|
38
41
|
engine = createUiTranslator({
|
|
39
42
|
storage: localStore(),
|
|
40
43
|
post: deps.post,
|
|
41
44
|
getVersion: deps.getVersion,
|
|
45
|
+
initialLanguage: deps.sharedLanguage?.(),
|
|
42
46
|
onChange: () => {
|
|
43
47
|
revision.value++;
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
const code = engine?.language ?? "en";
|
|
49
|
+
if (code !== language.value) deps.shareLanguage?.(code);
|
|
50
|
+
language.value = code;
|
|
51
|
+
applyHtmlLang(code);
|
|
46
52
|
},
|
|
47
53
|
});
|
|
48
54
|
language.value = engine.language;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.97.1-staging.
|
|
5
|
+
"version": "4.97.1-staging.732",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
package/plugins/ui-language.ts
CHANGED
|
@@ -23,7 +23,16 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
23
23
|
return $fetch(path, { ...init, retry: 0, headers: { Authorization: token } });
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// Same domain-wide cookie pattern as the theme (useThemePreference): one
|
|
27
|
+
// choice for all eleven apps, not one per app host.
|
|
28
|
+
const langCookie = () =>
|
|
29
|
+
nuxtApp.runWithContext(() => useCookie<string | null>("ui-lang", { ...cookieConfig, maxAge: 365 * 24 * 60 * 60 }));
|
|
30
|
+
|
|
26
31
|
installUiLanguage({
|
|
32
|
+
sharedLanguage: () => langCookie().value ?? undefined,
|
|
33
|
+
shareLanguage: (code) => {
|
|
34
|
+
langCookie().value = code;
|
|
35
|
+
},
|
|
27
36
|
post: (q, target) => call("/api/translations/v1", { method: "POST", body: { q, target } }),
|
|
28
37
|
getVersion: async () => ((await call("/api/translations/v1/version")) as any)?.version,
|
|
29
38
|
});
|
package/utils/ui-translate.ts
CHANGED
|
@@ -79,6 +79,8 @@ export type TranslatorDeps = {
|
|
|
79
79
|
post: (q: string[], target: string) => Promise<{ translations?: unknown; version?: unknown }>;
|
|
80
80
|
getVersion: () => Promise<unknown>;
|
|
81
81
|
onChange: () => void;
|
|
82
|
+
/** Language chosen in another app of the same domain (shared cookie); wins over storage. */
|
|
83
|
+
initialLanguage?: string;
|
|
82
84
|
now?: () => number;
|
|
83
85
|
schedule?: (fn: () => void, ms: number) => unknown;
|
|
84
86
|
};
|
|
@@ -101,7 +103,7 @@ export function createUiTranslator(deps: TranslatorDeps) {
|
|
|
101
103
|
const schedule = deps.schedule ?? ((fn: () => void, ms: number) => setTimeout(fn, ms));
|
|
102
104
|
|
|
103
105
|
const known = new Set(UI_LANGUAGES.map((l) => l.code));
|
|
104
|
-
const stored = safe(() => storage?.getItem(UI_TR_LANG_KEY) ?? "", "");
|
|
106
|
+
const stored = deps.initialLanguage || safe(() => storage?.getItem(UI_TR_LANG_KEY) ?? "", "");
|
|
105
107
|
let lang = known.has(stored) ? stored : "en";
|
|
106
108
|
let version = safe(() => storage?.getItem(UI_TR_VERSION_KEY) ?? "", "");
|
|
107
109
|
let dict: Record<string, string> = {};
|