@uipkge/nuxt 0.1.17 → 0.1.19

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/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.1.17",
7
+ "version": "0.1.19",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -69,6 +69,11 @@ const module$1 = defineNuxtModule({
69
69
  addPlugin({
70
70
  src: resolver.resolve("./runtime/plugin.suppress-warnings")
71
71
  });
72
+ } else {
73
+ addPlugin({
74
+ src: resolver.resolve("./runtime/plugin.cdn.client"),
75
+ mode: "client"
76
+ });
72
77
  }
73
78
  }
74
79
  });
@@ -1,8 +1,8 @@
1
- import { useAsyncData, useRuntimeConfig } from "#app";
1
+ import { useLazyAsyncData, useRuntimeConfig } from "#app";
2
2
  import { computed } from "vue";
3
3
  export function useI18nowLocales() {
4
4
  const { projectId, cdnUrl } = useRuntimeConfig().public.i18now;
5
- const { data, pending, error, refresh } = useAsyncData(
5
+ const { data, pending, error, refresh } = useLazyAsyncData(
6
6
  "i18now-locales",
7
7
  async () => {
8
8
  if (!projectId) return [];
@@ -13,7 +13,7 @@ export function useI18nowLocales() {
13
13
  if (!Array.isArray(data2)) return [];
14
14
  return data2;
15
15
  },
16
- { default: () => [] }
16
+ { default: () => [], server: false }
17
17
  );
18
18
  const locales = computed(() => data.value ?? []);
19
19
  const sourceLocale = computed(() => data.value?.find((l) => l.isSource) ?? null);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Production client plugin — handles CDN translation loading on locale switch.
3
+ *
4
+ * The server plugin loads translations for the initial SSR locale, but its
5
+ * i18n:beforeLocaleSwitch hook dies after the response. This lightweight client
6
+ * plugin re-registers the hook so locale switches load new CDN translations
7
+ * without a full page reload.
8
+ *
9
+ * For SPA/CSR routes (no SSR), it also loads the initial locale from CDN.
10
+ *
11
+ * No sync logic, no API key, no $t patching — zero overhead beyond the fetch.
12
+ */
13
+ declare const _default: (nuxtApp: unknown) => Promise<void>;
14
+ export default _default;
@@ -0,0 +1,28 @@
1
+ import { defineNuxtPlugin, useRuntimeConfig } from "#app";
2
+ export default defineNuxtPlugin(async (nuxtApp) => {
3
+ const { projectId, cdnUrl, environment, locale: configLocale } = useRuntimeConfig().public.i18now;
4
+ if (!projectId) return;
5
+ const i18n = nuxtApp.$i18n ?? nuxtApp.vueApp.config.globalProperties.$i18n;
6
+ const currentLocale = i18n?.locale?.value ?? i18n?.locale ?? configLocale;
7
+ async function loadLocale(locale) {
8
+ try {
9
+ const url = `${cdnUrl}/${projectId}/publish/${environment}/${locale}.json`;
10
+ const res = await fetch(url, { signal: AbortSignal.timeout(5e3) });
11
+ if (!res.ok) return;
12
+ const data = await res.json();
13
+ if (typeof data !== "object" || data === null || Array.isArray(data)) return;
14
+ if (i18n) i18n.mergeLocaleMessage(locale, data);
15
+ } catch {
16
+ }
17
+ }
18
+ const ssrKeys = nuxtApp.payload.i18nowCdnKeys;
19
+ if (!ssrKeys || ssrKeys.length === 0) {
20
+ await loadLocale(currentLocale);
21
+ }
22
+ let activeLocale = currentLocale;
23
+ nuxtApp.hook("i18n:beforeLocaleSwitch", async ({ newLocale }) => {
24
+ if (newLocale === activeLocale) return;
25
+ activeLocale = newLocale;
26
+ await loadLocale(newLocale);
27
+ });
28
+ });
@@ -87,7 +87,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
87
87
  return;
88
88
  }
89
89
  syncer.setExistingKeys(Object.keys(data));
90
- i18nGlobal?.setLocaleMessage(targetLocale, data);
90
+ i18nGlobal?.mergeLocaleMessage(targetLocale, data);
91
91
  } else {
92
92
  syncer.setExistingKeys([]);
93
93
  if (import.meta.dev) {
@@ -23,7 +23,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
23
23
  return;
24
24
  }
25
25
  const messages = data;
26
- if (i18n) i18n.setLocaleMessage(locale, messages);
26
+ if (i18n) i18n.mergeLocaleMessage(locale, messages);
27
27
  nuxtApp.payload.i18nowCdnKeys = Object.keys(messages);
28
28
  } catch (err) {
29
29
  if (import.meta.dev) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipkge/nuxt",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {