nuxt-i18n-micro 1.12.5 → 1.12.6

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,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/D1fvHJQV.js">
4
+ <link rel="modulepreload" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/m7X1zp9L.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/BpNRGTHy.js">
8
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DxMn4SAe.js">
7
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/3K8wcrOi.js">
8
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/Bb67euK9.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/DzdJBprQ.js">
11
- <script type="module" src="/__nuxt-i18n-micro/_nuxt/D1fvHJQV.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:"ad18ae07-58f1-41c2-b3b7-7ee23bfaa019",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
10
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CBnq9Yf3.js">
11
+ <script type="module" src="/__nuxt-i18n-micro/_nuxt/m7X1zp9L.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:"d4fcda60-d5e3-4685-ae1f-cdc4257a8754",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.d.mts CHANGED
@@ -15,6 +15,7 @@ interface ModuleOptions {
15
15
  defaultLocale?: string;
16
16
  translationDir?: string;
17
17
  autoDetectLanguage?: boolean;
18
+ autoDetectPath?: string;
18
19
  disableWatcher?: boolean;
19
20
  includeDefaultLocaleRoute?: boolean;
20
21
  routesLocaleLinks?: Record<string, string>;
package/dist/module.d.ts CHANGED
@@ -15,6 +15,7 @@ interface ModuleOptions {
15
15
  defaultLocale?: string;
16
16
  translationDir?: string;
17
17
  autoDetectLanguage?: boolean;
18
+ autoDetectPath?: string;
18
19
  disableWatcher?: boolean;
19
20
  includeDefaultLocaleRoute?: boolean;
20
21
  routesLocaleLinks?: Record<string, 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.12.5",
4
+ "version": "1.12.6",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.3",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -342,6 +342,7 @@ const module = defineNuxtModule({
342
342
  define: true,
343
343
  defaultLocale: "en",
344
344
  translationDir: "locales",
345
+ autoDetectPath: "*",
345
346
  autoDetectLanguage: true,
346
347
  disablePageLocales: false,
347
348
  disableWatcher: false,
@@ -375,6 +376,7 @@ const module = defineNuxtModule({
375
376
  defaultLocale: options.defaultLocale ?? "en",
376
377
  translationDir: options.translationDir ?? "locales",
377
378
  autoDetectLanguage: options.autoDetectLanguage ?? true,
379
+ autoDetectPath: options.autoDetectPath ?? "*",
378
380
  includeDefaultLocaleRoute: options.includeDefaultLocaleRoute ?? false,
379
381
  routesLocaleLinks: options.routesLocaleLinks ?? {},
380
382
  dateBuild: Date.now(),
@@ -399,7 +401,7 @@ const module = defineNuxtModule({
399
401
  if (options.autoDetectLanguage) {
400
402
  addPlugin({
401
403
  src: resolver.resolve("./runtime/plugins/04.auto-detect"),
402
- mode: "client",
404
+ mode: "server",
403
405
  order: 4
404
406
  });
405
407
  }
@@ -1,16 +1,22 @@
1
- import { defineNuxtPlugin, useCookie } from "#app";
1
+ import { defineNuxtPlugin, useCookie, useRequestHeaders, navigateTo } from "#app";
2
2
  import { useRoute, useRouter } from "#imports";
3
- export default defineNuxtPlugin(async ({ $config }) => {
4
- const i18nConfig = $config.public.i18nConfig;
3
+ export default defineNuxtPlugin(async (nuxtApp) => {
4
+ const i18nConfig = nuxtApp.$config.public.i18nConfig;
5
5
  const userLocaleCookie = useCookie("user-locale");
6
+ const headers = useRequestHeaders(["accept-language"]);
6
7
  const supportedLocales = i18nConfig.locales?.map((locale) => locale.code) ?? [];
7
8
  const defaultLocale = i18nConfig.defaultLocale || "en";
9
+ const autoDetectPath = i18nConfig.autoDetectPath || "*";
8
10
  if (userLocaleCookie.value) {
9
11
  return;
10
12
  }
11
13
  const router = useRouter();
12
14
  const route = useRoute();
13
- const browserLanguages = navigator.languages || [navigator.language];
15
+ if (autoDetectPath !== "*" && route.path !== autoDetectPath) {
16
+ return;
17
+ }
18
+ const acceptLanguage = headers?.["accept-language"] ?? "";
19
+ const browserLanguages = acceptLanguage ? acceptLanguage.split(",").map((lang) => lang.split(";")[0]) : [defaultLocale];
14
20
  let detectedLocale = defaultLocale;
15
21
  for (const language of browserLanguages) {
16
22
  const primaryLanguage = language.split("-")[0];
@@ -21,17 +27,20 @@ export default defineNuxtPlugin(async ({ $config }) => {
21
27
  }
22
28
  if (supportedLocales.includes(detectedLocale)) {
23
29
  const currentPath = router.currentRoute;
30
+ const currentLocale = currentPath.value.params.locale ?? defaultLocale;
31
+ if (detectedLocale === currentLocale) {
32
+ return;
33
+ }
24
34
  const resolvedRoute = router.resolve(currentPath.value);
25
35
  const routeName = resolvedRoute.name.replace(`localized-`, "");
26
- const { defaultLocale: defaultLocale2 } = i18nConfig;
27
- const newRouteName = detectedLocale === defaultLocale2 ? routeName : `localized-${routeName}`;
36
+ const newRouteName = detectedLocale === defaultLocale ? routeName : `localized-${routeName}`;
28
37
  const newParams = { ...route.params };
29
38
  delete newParams.locale;
30
- if (detectedLocale !== defaultLocale2) {
39
+ if (detectedLocale !== defaultLocale) {
31
40
  newParams.locale = detectedLocale;
32
41
  }
33
42
  userLocaleCookie.value = detectedLocale;
34
- location.href = router.resolve({ name: newRouteName, params: newParams }).href;
43
+ await navigateTo(router.resolve({ name: newRouteName, params: newParams }).href, { redirectCode: 301, external: true });
35
44
  } else {
36
45
  userLocaleCookie.value = defaultLocale;
37
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.12.5",
3
+ "version": "1.12.6",
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",