@uipkge/nuxt 0.1.15 → 0.1.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/README.md CHANGED
@@ -104,12 +104,23 @@ i18now: {
104
104
 
105
105
  ## Playground
106
106
 
107
- A minimal playground is included in `playground/`. To run it:
107
+ A minimal playground is included in `playground/`. It runs on **port 3227**.
108
108
 
109
109
  ```bash
110
110
  pnpm dev:playground
111
111
  ```
112
112
 
113
+ ### Framework playground ports
114
+
115
+ All SDK playgrounds use fixed ports so they can run simultaneously alongside the i18now server (port 3220):
116
+
117
+ | Package | Port |
118
+ |---|---|
119
+ | `@uipkge/react` | 3224 |
120
+ | `@uipkge/vue` | 3225 |
121
+ | `@uipkge/next` | 3226 |
122
+ | `@uipkge/nuxt` | 3227 |
123
+
113
124
  ## Building locally
114
125
 
115
126
  ```bash
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.1.15",
7
+ "version": "0.1.17",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -49,11 +49,18 @@ const module$1 = defineNuxtModule({
49
49
  src: resolver.resolve("./runtime/plugin"),
50
50
  mode: "server"
51
51
  });
52
- addImports({
53
- name: "useI18now",
54
- as: "useI18now",
55
- from: resolver.resolve("./runtime/composables/useI18n")
56
- });
52
+ addImports([
53
+ {
54
+ name: "useI18now",
55
+ as: "useI18now",
56
+ from: resolver.resolve("./runtime/composables/useI18n")
57
+ },
58
+ {
59
+ name: "useI18nowLocales",
60
+ as: "useI18nowLocales",
61
+ from: resolver.resolve("./runtime/composables/useI18nowLocales")
62
+ }
63
+ ]);
57
64
  if (nuxt.options.dev) {
58
65
  addPlugin({
59
66
  src: resolver.resolve("./runtime/plugin.client"),
@@ -0,0 +1,34 @@
1
+ export interface I18nowLocale {
2
+ code: string;
3
+ name: string;
4
+ nativeName: string;
5
+ isSource: boolean;
6
+ }
7
+ /**
8
+ * Returns the list of locales published in the i18now dashboard.
9
+ *
10
+ * Fetches `{cdnUrl}/{projectId}/locales.json` (written on every publish)
11
+ * so the app auto-discovers new languages without code changes or redeployment.
12
+ *
13
+ * Usage:
14
+ * ```vue
15
+ * <script setup>
16
+ * const { locales, sourceLocale, pending } = useI18nowLocales()
17
+ * </script>
18
+ *
19
+ * <template>
20
+ * <select @change="setLocale($event.target.value)">
21
+ * <option v-for="l in locales" :key="l.code" :value="l.code">
22
+ * {{ l.nativeName }}
23
+ * </option>
24
+ * </select>
25
+ * </template>
26
+ * ```
27
+ */
28
+ export declare function useI18nowLocales(): {
29
+ locales: import("vue").ComputedRef<any>;
30
+ sourceLocale: import("vue").ComputedRef<any>;
31
+ pending: any;
32
+ error: any;
33
+ refresh: any;
34
+ };
@@ -0,0 +1,21 @@
1
+ import { useAsyncData, useRuntimeConfig } from "#app";
2
+ import { computed } from "vue";
3
+ export function useI18nowLocales() {
4
+ const { projectId, cdnUrl } = useRuntimeConfig().public.i18now;
5
+ const { data, pending, error, refresh } = useAsyncData(
6
+ "i18now-locales",
7
+ async () => {
8
+ if (!projectId) return [];
9
+ const url = `${cdnUrl}/${projectId}/locales.json`;
10
+ const res = await fetch(url, { signal: AbortSignal.timeout(5e3) });
11
+ if (!res.ok) return [];
12
+ const data2 = await res.json();
13
+ if (!Array.isArray(data2)) return [];
14
+ return data2;
15
+ },
16
+ { default: () => [] }
17
+ );
18
+ const locales = computed(() => data.value ?? []);
19
+ const sourceLocale = computed(() => data.value?.find((l) => l.isSource) ?? null);
20
+ return { locales, sourceLocale, pending, error, refresh };
21
+ }
@@ -107,7 +107,13 @@ export default defineNuxtPlugin(async (nuxtApp) => {
107
107
  }
108
108
  }
109
109
  }
110
- await loadLocale(locale);
110
+ let currentLocale = locale;
111
+ const ssrKeys = nuxtApp.payload.i18nowCdnKeys;
112
+ if (ssrKeys && ssrKeys.length > 0) {
113
+ syncer.setExistingKeys(ssrKeys);
114
+ } else {
115
+ await loadLocale(locale);
116
+ }
111
117
  const originalGlobalT = nuxtApp.vueApp.config.globalProperties.$t;
112
118
  if (originalGlobalT) {
113
119
  nuxtApp.vueApp.config.globalProperties.$t = function(key, defaultValue, ...rest) {
@@ -120,6 +126,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
120
126
  };
121
127
  }
122
128
  nuxtApp.hook("i18n:beforeLocaleSwitch", async ({ newLocale }) => {
129
+ if (newLocale === currentLocale) return;
130
+ currentLocale = newLocale;
123
131
  await loadLocale(newLocale);
124
132
  });
125
133
  return {
@@ -24,6 +24,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
24
24
  }
25
25
  const messages = data;
26
26
  if (i18n) i18n.setLocaleMessage(locale, messages);
27
+ nuxtApp.payload.i18nowCdnKeys = Object.keys(messages);
27
28
  } catch (err) {
28
29
  if (import.meta.dev) {
29
30
  console.warn(`[i18now] Failed to load locale '${locale}' from CDN:`, err);
@@ -31,8 +32,11 @@ export default defineNuxtPlugin(async (nuxtApp) => {
31
32
  }
32
33
  }
33
34
  const currentLocale = i18n?.locale?.value ?? i18n?.locale ?? configLocale;
35
+ let activeLocale = currentLocale;
34
36
  await loadLocale(currentLocale);
35
37
  nuxtApp.hook("i18n:beforeLocaleSwitch", async ({ newLocale }) => {
38
+ if (newLocale === activeLocale) return;
39
+ activeLocale = newLocale;
36
40
  await loadLocale(newLocale);
37
41
  });
38
42
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipkge/nuxt",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -42,7 +42,7 @@
42
42
  "scripts": {
43
43
  "build": "nuxt-module-build build",
44
44
  "dev": "nuxt-module-build prepare",
45
- "dev:playground": "nuxi dev playground",
45
+ "dev:playground": "nuxi dev playground --port 3227",
46
46
  "test": "vitest run",
47
47
  "test:watch": "vitest",
48
48
  "test:coverage": "vitest run --coverage",