nuxt-i18n-micro 1.12.4 → 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.
- package/dist/client/200.html +6 -6
- package/dist/client/404.html +6 -6
- package/dist/client/_nuxt/{BpNRGTHy.js → 3K8wcrOi.js} +1 -1
- package/dist/client/_nuxt/{DxMn4SAe.js → Bb67euK9.js} +1 -1
- package/dist/client/_nuxt/{DzdJBprQ.js → CBnq9Yf3.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/d4fcda60-d5e3-4685-ae1f-cdc4257a8754.json +1 -0
- package/dist/client/_nuxt/m7X1zp9L.js +119 -0
- package/dist/client/index.html +6 -6
- package/dist/module.d.mts +1 -0
- package/dist/module.d.ts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +14 -3
- package/dist/runtime/plugins/04.auto-detect.js +17 -8
- package/package.json +1 -1
- package/dist/client/_nuxt/D1fvHJQV.js +0 -119
- package/dist/client/_nuxt/builds/meta/4d2d24d4-fadc-4442-9bd0-66e78e57f4d0.json +0 -1
package/dist/client/index.html
CHANGED
|
@@ -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/
|
|
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/
|
|
8
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/
|
|
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/
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"
|
|
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
package/dist/module.d.ts
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { useNuxt, defineNuxtModule, createResolver, addPlugin, addImportsDir, addServerHandler, addComponentsDir, extendPages } from '@nuxt/kit';
|
|
2
|
+
import { useNuxt, defineNuxtModule, createResolver, addPlugin, addImportsDir, addServerHandler, addComponentsDir, extendPages, addPrerenderRoutes } from '@nuxt/kit';
|
|
3
3
|
import { watch } from 'chokidar';
|
|
4
4
|
import * as fs from 'node:fs';
|
|
5
5
|
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
@@ -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: "
|
|
404
|
+
mode: "server",
|
|
403
405
|
order: 4
|
|
404
406
|
});
|
|
405
407
|
}
|
|
@@ -420,11 +422,20 @@ const module = defineNuxtModule({
|
|
|
420
422
|
extensions: ["vue"]
|
|
421
423
|
});
|
|
422
424
|
extendPages((pages) => {
|
|
425
|
+
const pagesNames = pages.map((page) => page.name).filter((name) => name !== void 0 && (!options.routesLocaleLinks || !options.routesLocaleLinks[name]));
|
|
423
426
|
if (!options.disableWatcher) {
|
|
424
|
-
const pagesNames = pages.map((page) => page.name).filter((name) => name !== void 0 && (!options.routesLocaleLinks || !options.routesLocaleLinks[name]));
|
|
425
427
|
localeManager.ensureTranslationFilesExist(pagesNames, options.translationDir, nuxt.options.rootDir);
|
|
426
428
|
}
|
|
427
429
|
pageManager.extendPages(pages, options, nuxt.options.rootDir);
|
|
430
|
+
nuxt.options.generate.routes = Array.isArray(nuxt.options.generate.routes) ? nuxt.options.generate.routes : [];
|
|
431
|
+
localeManager.locales.forEach((locale) => {
|
|
432
|
+
if (!options.disablePageLocales) {
|
|
433
|
+
pagesNames.forEach((name) => {
|
|
434
|
+
addPrerenderRoutes(`/_locales/${name}/${locale.code}/data.json`);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
addPrerenderRoutes(`/_locales/general/${locale.code}/data.json`);
|
|
438
|
+
});
|
|
428
439
|
});
|
|
429
440
|
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
430
441
|
const routes = nitroConfig.prerender?.routes || [];
|
|
@@ -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 (
|
|
4
|
-
const 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
|
-
|
|
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
|
|
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 !==
|
|
39
|
+
if (detectedLocale !== defaultLocale) {
|
|
31
40
|
newParams.locale = detectedLocale;
|
|
32
41
|
}
|
|
33
42
|
userLocaleCookie.value = detectedLocale;
|
|
34
|
-
|
|
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.
|
|
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",
|