nuxt-i18n-micro 1.16.0 → 1.17.0-1726909148.4207cd6

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.
@@ -1 +1 @@
1
- {"id":"613b2437-64f2-42a2-8c2d-9c1b0007ae86","timestamp":1726489011724}
1
+ {"id":"8c5651b7-8282-4881-9c94-76b6a4976d1f","timestamp":1726909154862}
@@ -0,0 +1 @@
1
+ {"id":"8c5651b7-8282-4881-9c94-76b6a4976d1f","timestamp":1726909154862,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -1,12 +1,12 @@
1
1
  <!DOCTYPE html><html data-capo=""><head><meta charset="utf-8">
2
2
  <meta name="viewport" content="width=device-width, initial-scale=1">
3
3
  <link rel="stylesheet" href="/__nuxt-i18n-micro/_nuxt/entry.DjxsrOxm.css">
4
- <link rel="modulepreload" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CCUdfIr-.js">
4
+ <link rel="modulepreload" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DLyXNYo2.js">
5
5
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/B6E6ObS_.js">
6
6
  <link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-404.D-AvUzLt.css">
7
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CUbs-yQQ.js">
8
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CLjGsY26.js">
7
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/C1JBbjFJ.js">
8
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/C-3exr1n.js">
9
9
  <link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.21ZDxC33.css">
10
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/BraUkLq2.js">
11
- <script type="module" src="/__nuxt-i18n-micro/_nuxt/CCUdfIr-.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"serverRendered":1},false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"613b2437-64f2-42a2-8c2d-9c1b0007ae86",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
10
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CtWyte3o.js">
11
+ <script type="module" src="/__nuxt-i18n-micro/_nuxt/DLyXNYo2.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"serverRendered":1},false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"8c5651b7-8282-4881-9c94-76b6a4976d1f",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.d.mts CHANGED
@@ -30,6 +30,7 @@ interface ModuleOptionsExtend extends ModuleOptions {
30
30
  plural: string;
31
31
  dateBuild: number;
32
32
  baseURL: string;
33
+ hashMode: boolean;
33
34
  }
34
35
  interface ModulePrivateOptionsExtend extends ModuleOptions {
35
36
  rootDir: string;
package/dist/module.d.ts CHANGED
@@ -30,6 +30,7 @@ interface ModuleOptionsExtend extends ModuleOptions {
30
30
  plural: string;
31
31
  dateBuild: number;
32
32
  baseURL: string;
33
+ hashMode: boolean;
33
34
  }
34
35
  interface ModulePrivateOptionsExtend extends ModuleOptions {
35
36
  rootDir: string;
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
3
  "configKey": "i18n",
4
- "version": "1.16.0",
4
+ "version": "1.17.0-1726909148.4207cd6",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -149,12 +149,15 @@ class PageManager {
149
149
  activeLocaleCodes;
150
150
  constructor(locales, defaultLocaleCode, includeDefaultLocaleRoute) {
151
151
  this.locales = locales;
152
- this.defaultLocale = this.findDefaultLocale(defaultLocaleCode);
152
+ this.defaultLocale = this.findLocaleByCode(defaultLocaleCode) || { code: defaultLocaleCode };
153
153
  this.includeDefaultLocaleRoute = includeDefaultLocaleRoute;
154
- this.activeLocaleCodes = this.calculateActiveLocaleCodes();
154
+ this.activeLocaleCodes = this.computeActiveLocaleCodes();
155
155
  }
156
- findDefaultLocale(defaultLocaleCode) {
157
- return this.locales.find((locale) => locale.code === defaultLocaleCode) || { code: defaultLocaleCode };
156
+ findLocaleByCode(code) {
157
+ return this.locales.find((locale) => locale.code === code);
158
+ }
159
+ computeActiveLocaleCodes() {
160
+ return this.locales.filter((locale) => locale.code !== this.defaultLocale.code || this.includeDefaultLocaleRoute).map((locale) => locale.code);
158
161
  }
159
162
  extendPages(pages, rootDir) {
160
163
  this.localizedPaths = this.extractLocalizedPaths(pages, rootDir);
@@ -162,9 +165,6 @@ class PageManager {
162
165
  pages.forEach((page) => this.localizePage(page, additionalRoutes));
163
166
  pages.push(...additionalRoutes);
164
167
  }
165
- calculateActiveLocaleCodes() {
166
- return this.locales.filter((locale) => locale.code !== this.defaultLocale.code || this.includeDefaultLocaleRoute).map((locale) => locale.code);
167
- }
168
168
  extractLocalizedPaths(pages, rootDir, parentPath = "") {
169
169
  const localizedPaths = {};
170
170
  pages.forEach((page) => {
@@ -390,7 +390,8 @@ const module = defineNuxtModule({
390
390
  routesLocaleLinks: options.routesLocaleLinks ?? {},
391
391
  fallbackLocale: options.fallbackLocale ?? void 0,
392
392
  dateBuild: Date.now(),
393
- baseURL: nuxt.options.app.baseURL
393
+ baseURL: nuxt.options.app.baseURL,
394
+ hashMode: nuxt.options?.router?.options?.hashMode ?? false
394
395
  };
395
396
  nuxt.options.runtimeConfig.i18nConfig = {
396
397
  rootDir: nuxt.options.rootDir,
@@ -1,6 +1,6 @@
1
1
  import { useTranslationHelper } from "../translationHelper.js";
2
2
  import { defineNuxtPlugin, useRuntimeConfig } from "#app";
3
- import { useRoute, useRouter } from "#imports";
3
+ import { useRoute, useRouter, useCookie } from "#imports";
4
4
  const i18nHelper = useTranslationHelper();
5
5
  const isDev = process.env.NODE_ENV !== "production";
6
6
  function interpolate(template, params) {
@@ -10,7 +10,10 @@ function interpolate(template, params) {
10
10
  }
11
11
  return result;
12
12
  }
13
- function getCurrentLocale(route, i18nConfig) {
13
+ function getCurrentLocale(route, i18nConfig, hashLocale) {
14
+ if (i18nConfig.hashMode && hashLocale) {
15
+ return hashLocale;
16
+ }
14
17
  return (route.params?.locale ?? i18nConfig.defaultLocale).toString();
15
18
  }
16
19
  function getRouteName(route, locale) {
@@ -26,6 +29,10 @@ function switchLocale(fromLocale, toLocale, route, router, i18nConfig) {
26
29
  if (router.hasRoute(`localized-${routeName}-${toLocale}`)) {
27
30
  const newParams2 = { ...route.params };
28
31
  newParams2.locale = toLocale;
32
+ if (i18nConfig.hashMode) {
33
+ const userLocaleCookie = useCookie("hash-locale");
34
+ userLocaleCookie.value = toLocale;
35
+ }
29
36
  return router.push({
30
37
  params: newParams2,
31
38
  name: `localized-${routeName}-${toLocale}`
@@ -37,10 +44,14 @@ function switchLocale(fromLocale, toLocale, route, router, i18nConfig) {
37
44
  if (toLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute) {
38
45
  newParams.locale = toLocale;
39
46
  }
47
+ if (i18nConfig.hashMode) {
48
+ const userLocaleCookie = useCookie("hash-locale");
49
+ userLocaleCookie.value = toLocale;
50
+ }
40
51
  return router.push({ name: newRouteName, params: newParams });
41
52
  }
42
- function getLocalizedRoute(to, router, route, i18nConfig, locale) {
43
- const currentLocale = locale || getCurrentLocale(route, i18nConfig);
53
+ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
54
+ const currentLocale = locale || getCurrentLocale(route, i18nConfig, hashLocale);
44
55
  const selectRoute = router.resolve(to);
45
56
  const routeName = getRouteName(selectRoute, currentLocale);
46
57
  const resolveParams = (to2) => {
@@ -93,7 +104,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
93
104
  }
94
105
  };
95
106
  useRouter().beforeEach(async (to, from, next) => {
96
- const locale = getCurrentLocale(to, i18nConfig);
107
+ const hashLocale2 = i18nConfig.hashMode ? nuxtApp.runWithContext(() => (useCookie("hash-locale").value ?? i18nConfig.defaultLocale).toString()).toString() : null;
108
+ const locale = getCurrentLocale(to, i18nConfig, hashLocale2);
97
109
  if (!i18nHelper.hasGeneralTranslation(locale)) {
98
110
  const data = await $fetch(`/_locales/general/${locale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
99
111
  await i18nHelper.loadTranslations(locale, data ?? {});
@@ -110,7 +122,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
110
122
  });
111
123
  const getTranslation = (key, params, defaultValue) => {
112
124
  if (!key) return "";
113
- const locale = getCurrentLocale(useRoute(), i18nConfig);
125
+ const hashLocale2 = i18nConfig.hashMode ? (useCookie("hash-locale").value ?? i18nConfig.defaultLocale).toString() : null;
126
+ const locale = getCurrentLocale(useRoute(), i18nConfig, hashLocale2);
114
127
  const routeName = getRouteName(useRoute(), locale);
115
128
  let value = i18nHelper.getTranslation(locale, routeName, key);
116
129
  if (!value) {
@@ -121,26 +134,31 @@ export default defineNuxtPlugin(async (nuxtApp) => {
121
134
  }
122
135
  return typeof value === "string" && params ? interpolate(value, params) : value;
123
136
  };
137
+ let hashLocale = null;
138
+ if (i18nConfig.hashMode) {
139
+ hashLocale = useCookie("hash-locale").value ?? i18nConfig.defaultLocale;
140
+ }
124
141
  return {
125
142
  provide: {
126
- getLocale: () => getCurrentLocale(useRoute(), i18nConfig),
143
+ getLocale: () => getCurrentLocale(useRoute(), i18nConfig, hashLocale),
144
+ // getLocale: () => getCurrentLocale(useRoute(), i18nConfig, i18nConfig.hashMode ? (hashLocale.value ?? i18nConfig.defaultLocale!).toString() : null),
127
145
  getLocales: () => i18nConfig.locales || [],
128
146
  getRouteName: (route, locale) => {
129
- const selectedLocale = locale ?? getCurrentLocale(useRoute(), i18nConfig);
147
+ const selectedLocale = locale ?? getCurrentLocale(useRoute(), i18nConfig, hashLocale);
130
148
  const selectedRoute = route ?? useRoute();
131
149
  return getRouteName(selectedRoute, selectedLocale);
132
150
  },
133
151
  t: getTranslation,
134
152
  tc: (key, count, defaultValue) => {
135
- const currentLocale = getCurrentLocale(useRoute(), i18nConfig);
153
+ const currentLocale = getCurrentLocale(useRoute(), i18nConfig, hashLocale);
136
154
  return plural(key, count, currentLocale, getTranslation) ?? defaultValue ?? key;
137
155
  },
138
156
  tn: (value, options) => {
139
- const locale = getCurrentLocale(useRoute(), i18nConfig);
157
+ const locale = getCurrentLocale(useRoute(), i18nConfig, hashLocale);
140
158
  return formatNumber(value, locale, options);
141
159
  },
142
160
  td: (value, options) => {
143
- const locale = getCurrentLocale(useRoute(), i18nConfig);
161
+ const locale = getCurrentLocale(useRoute(), i18nConfig, hashLocale);
144
162
  return formatDate(value, locale, options);
145
163
  },
146
164
  has: (key) => {
@@ -148,20 +166,23 @@ export default defineNuxtPlugin(async (nuxtApp) => {
148
166
  },
149
167
  mergeTranslations: (newTranslations) => {
150
168
  const route = useRoute();
151
- const locale = getCurrentLocale(route, i18nConfig);
169
+ const locale = getCurrentLocale(route, i18nConfig, hashLocale);
152
170
  const routeName = getRouteName(route, locale);
153
171
  i18nHelper.mergeTranslation(locale, routeName, newTranslations);
154
172
  },
155
173
  switchLocale: (toLocale) => {
156
174
  const router = useRouter();
157
175
  const route = useRoute();
158
- const fromLocale = getCurrentLocale(route, i18nConfig);
176
+ const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale);
177
+ if (i18nConfig.hashMode) {
178
+ hashLocale = toLocale;
179
+ }
159
180
  switchLocale(fromLocale, toLocale, route, router, i18nConfig);
160
181
  },
161
182
  localeRoute: (to, locale) => {
162
183
  const router = useRouter();
163
184
  const route = useRoute();
164
- return getLocalizedRoute(to, router, route, i18nConfig, locale);
185
+ return getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale);
165
186
  }
166
187
  }
167
188
  };
@@ -3,6 +3,7 @@ import { useRoute, useRouter } from "#imports";
3
3
  export default defineNuxtPlugin(async (nuxtApp) => {
4
4
  const i18nConfig = nuxtApp.$config.public.i18nConfig;
5
5
  const userLocaleCookie = useCookie(i18nConfig.localeCookie || "user-locale");
6
+ const hashCookie = useCookie("hash-locale");
6
7
  const headers = useRequestHeaders(["accept-language"]);
7
8
  const supportedLocales = i18nConfig.locales?.map((locale) => locale.code) ?? [];
8
9
  const defaultLocale = i18nConfig.defaultLocale || "en";
@@ -30,6 +31,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
30
31
  const currentLocale = currentPath.value.params.locale ?? defaultLocale;
31
32
  if (detectedLocale === currentLocale) {
32
33
  userLocaleCookie.value = detectedLocale;
34
+ if (i18nConfig.hashMode) {
35
+ hashCookie.value = detectedLocale;
36
+ }
33
37
  return;
34
38
  }
35
39
  const resolvedRoute = router.resolve(currentPath.value);
@@ -41,8 +45,14 @@ export default defineNuxtPlugin(async (nuxtApp) => {
41
45
  newParams.locale = detectedLocale;
42
46
  }
43
47
  userLocaleCookie.value = detectedLocale;
48
+ if (i18nConfig.hashMode) {
49
+ hashCookie.value = detectedLocale;
50
+ }
44
51
  await navigateTo(router.resolve({ name: newRouteName, params: newParams }).href, { redirectCode: 301, external: true });
45
52
  } else {
46
53
  userLocaleCookie.value = defaultLocale;
54
+ if (i18nConfig.hashMode) {
55
+ hashCookie.value = detectedLocale;
56
+ }
47
57
  }
48
58
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.16.0",
3
+ "version": "1.17.0-1726909148.4207cd6",
4
4
  "description": "Nuxt I18n Micro is a lightweight, high-performance internationalization module for Nuxt, designed to handle multi-language support with minimal overhead, fast build times, and efficient runtime performance.",
5
5
  "repository": "s00d/nuxt-i18n-micro",
6
6
  "license": "MIT",
@@ -45,6 +45,7 @@
45
45
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
46
46
  "dev:generate": "nuxi generate playground",
47
47
  "release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
48
+ "prerelease": "npm run lint && npm run test && npm run prepack && changelogen --canary --publish && npm publish --tag next && git push --follow-tags",
48
49
  "lint": "eslint .",
49
50
  "lint:fix": "eslint . --fix",
50
51
  "test": "playwright test --grep-invert \"test/performance\\.test\\.ts\"",