nuxt-i18n-micro 1.12.5 → 1.13.0
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 +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/5b99a708-0632-41fc-89b6-3b4ae1aff60c.json +1 -0
- package/dist/client/index.html +1 -1
- package/dist/module.d.mts +1 -0
- package/dist/module.d.ts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +3 -1
- package/dist/runtime/composables/useI18n.js +1 -0
- package/dist/runtime/plugins/01.plugin.d.ts +4 -1
- package/dist/runtime/plugins/01.plugin.js +5 -0
- package/dist/runtime/plugins/04.auto-detect.js +17 -8
- package/package.json +1 -1
- package/dist/client/_nuxt/builds/meta/ad18ae07-58f1-41c2-b3b7-7ee23bfaa019.json +0 -1
package/dist/client/200.html
CHANGED
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.21ZDxC33.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DzdJBprQ.js">
|
|
11
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:"
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"5b99a708-0632-41fc-89b6-3b4ae1aff60c",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/client/404.html
CHANGED
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.21ZDxC33.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DzdJBprQ.js">
|
|
11
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:"
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"5b99a708-0632-41fc-89b6-3b4ae1aff60c",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"5b99a708-0632-41fc-89b6-3b4ae1aff60c","timestamp":1725447038241}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"5b99a708-0632-41fc-89b6-3b4ae1aff60c","timestamp":1725447038241,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.21ZDxC33.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DzdJBprQ.js">
|
|
11
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:"
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"5b99a708-0632-41fc-89b6-3b4ae1aff60c",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
|
@@ -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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RouteLocationRaw } from 'vue-router';
|
|
1
|
+
import type { RouteLocationNormalizedLoaded, RouteLocationRaw, RouteLocationResolvedGeneric } from 'vue-router';
|
|
2
2
|
import type { Locale } from '../../types.js';
|
|
3
3
|
export interface Translations {
|
|
4
4
|
[key: string]: string | number | boolean | Translations | PluralTranslations | unknown[] | null;
|
|
@@ -10,6 +10,7 @@ interface PluralTranslations {
|
|
|
10
10
|
declare const _default: import("#app").Plugin<{
|
|
11
11
|
getLocale: () => string;
|
|
12
12
|
getLocales: () => Locale[];
|
|
13
|
+
getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) => string;
|
|
13
14
|
t: (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
|
|
14
15
|
tc: (key: string, count: number, defaultValue?: string) => string;
|
|
15
16
|
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
@@ -21,6 +22,7 @@ declare const _default: import("#app").Plugin<{
|
|
|
21
22
|
}> & import("#app").ObjectPlugin<{
|
|
22
23
|
getLocale: () => string;
|
|
23
24
|
getLocales: () => Locale[];
|
|
25
|
+
getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) => string;
|
|
24
26
|
t: (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
|
|
25
27
|
tc: (key: string, count: number, defaultValue?: string) => string;
|
|
26
28
|
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
@@ -34,6 +36,7 @@ export default _default;
|
|
|
34
36
|
export interface PluginsInjections {
|
|
35
37
|
$getLocale: () => string;
|
|
36
38
|
$getLocales: () => Locale[];
|
|
39
|
+
$getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) => string;
|
|
37
40
|
$t: <T extends Record<string, string | number | boolean>>(key: string, params?: T, defaultValue?: string) => string | number | boolean | Translations | PluralTranslations | unknown[] | unknown | null;
|
|
38
41
|
$tc: (key: string, count: number, defaultValue?: string) => string;
|
|
39
42
|
$tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
@@ -123,6 +123,11 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
123
123
|
provide: {
|
|
124
124
|
getLocale: () => getCurrentLocale(useRoute(), i18nConfig),
|
|
125
125
|
getLocales: () => i18nConfig.locales || [],
|
|
126
|
+
getRouteName: (route2, locale) => {
|
|
127
|
+
const selectedLocale = locale ?? getCurrentLocale(useRoute(), i18nConfig);
|
|
128
|
+
const selectedRoute = route2 ?? useRoute();
|
|
129
|
+
return getRouteName(selectedRoute, selectedLocale);
|
|
130
|
+
},
|
|
126
131
|
t: getTranslation,
|
|
127
132
|
tc: (key, count, defaultValue) => {
|
|
128
133
|
const translation = getTranslation(key, {}, defaultValue);
|
|
@@ -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.
|
|
3
|
+
"version": "1.13.0",
|
|
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",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"ad18ae07-58f1-41c2-b3b7-7ee23bfaa019","timestamp":1725441916359,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|