nuxt-i18n-micro 1.13.0 → 1.13.2
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/1f40d9d0-1d86-4ceb-b98c-da56e66c6bdb.json +1 -0
- package/dist/client/index.html +1 -1
- package/dist/module.d.mts +5 -2
- package/dist/module.d.ts +5 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +8 -6
- package/dist/runtime/plugins/01.plugin.d.ts +1 -1
- package/dist/runtime/plugins/01.plugin.js +2 -2
- package/dist/runtime/plugins/03.define.d.ts +2 -2
- package/dist/runtime/plugins/03.define.js +21 -18
- package/dist/runtime/server/middleware/i18n-loader.js +2 -1
- package/package.json +1 -1
- package/dist/client/_nuxt/builds/meta/5b99a708-0632-41fc-89b6-3b4ae1aff60c.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:"1f40d9d0-1d86-4ceb-b98c-da56e66c6bdb",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:"1f40d9d0-1d86-4ceb-b98c-da56e66c6bdb",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"1f40d9d0-1d86-4ceb-b98c-da56e66c6bdb","timestamp":1725460561569}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"1f40d9d0-1d86-4ceb-b98c-da56e66c6bdb","timestamp":1725460561569,"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:"1f40d9d0-1d86-4ceb-b98c-da56e66c6bdb",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.d.mts
CHANGED
|
@@ -23,12 +23,14 @@ interface ModuleOptions {
|
|
|
23
23
|
disablePageLocales?: boolean;
|
|
24
24
|
}
|
|
25
25
|
interface ModuleOptionsExtend extends ModuleOptions {
|
|
26
|
-
rootDir: string;
|
|
27
26
|
plural: string;
|
|
28
|
-
rootDirs: string[];
|
|
29
27
|
dateBuild: number;
|
|
30
28
|
baseURL: string;
|
|
31
29
|
}
|
|
30
|
+
interface ModulePrivateOptionsExtend extends ModuleOptions {
|
|
31
|
+
rootDir: string;
|
|
32
|
+
rootDirs: string[];
|
|
33
|
+
}
|
|
32
34
|
|
|
33
35
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
34
36
|
|
|
@@ -37,6 +39,7 @@ interface ModuleHooks {
|
|
|
37
39
|
}
|
|
38
40
|
declare module '@nuxt/schema' {
|
|
39
41
|
interface ConfigSchema {
|
|
42
|
+
i18nConfig?: ModulePrivateOptionsExtend;
|
|
40
43
|
publicRuntimeConfig?: {
|
|
41
44
|
i18nConfig?: ModuleOptionsExtend;
|
|
42
45
|
};
|
package/dist/module.d.ts
CHANGED
|
@@ -23,12 +23,14 @@ interface ModuleOptions {
|
|
|
23
23
|
disablePageLocales?: boolean;
|
|
24
24
|
}
|
|
25
25
|
interface ModuleOptionsExtend extends ModuleOptions {
|
|
26
|
-
rootDir: string;
|
|
27
26
|
plural: string;
|
|
28
|
-
rootDirs: string[];
|
|
29
27
|
dateBuild: number;
|
|
30
28
|
baseURL: string;
|
|
31
29
|
}
|
|
30
|
+
interface ModulePrivateOptionsExtend extends ModuleOptions {
|
|
31
|
+
rootDir: string;
|
|
32
|
+
rootDirs: string[];
|
|
33
|
+
}
|
|
32
34
|
|
|
33
35
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
34
36
|
|
|
@@ -37,6 +39,7 @@ interface ModuleHooks {
|
|
|
37
39
|
}
|
|
38
40
|
declare module '@nuxt/schema' {
|
|
39
41
|
interface ConfigSchema {
|
|
42
|
+
i18nConfig?: ModulePrivateOptionsExtend;
|
|
40
43
|
publicRuntimeConfig?: {
|
|
41
44
|
i18nConfig?: ModuleOptionsExtend;
|
|
42
45
|
};
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -39,7 +39,7 @@ function setupDevToolsUI(options, resolve) {
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
async getLocalesAndTranslations() {
|
|
42
|
-
const rootDirs = nuxt.options.runtimeConfig.
|
|
42
|
+
const rootDirs = nuxt.options.runtimeConfig.i18nConfig?.rootDirs || [nuxt.options.rootDir];
|
|
43
43
|
const localesData = [];
|
|
44
44
|
for (const rootDir of rootDirs) {
|
|
45
45
|
const localesDir = path.join(rootDir, options.translationDir || "locales");
|
|
@@ -156,7 +156,7 @@ class PageManager {
|
|
|
156
156
|
findDefaultLocale(defaultLocaleCode) {
|
|
157
157
|
return this.locales.find((locale) => locale.code === defaultLocaleCode) || { code: defaultLocaleCode };
|
|
158
158
|
}
|
|
159
|
-
extendPages(pages,
|
|
159
|
+
extendPages(pages, rootDir) {
|
|
160
160
|
this.localizedPaths = this.extractLocalizedPaths(pages, rootDir);
|
|
161
161
|
const additionalRoutes = [];
|
|
162
162
|
pages.forEach((page) => this.localizePage(page, additionalRoutes));
|
|
@@ -365,8 +365,6 @@ const module = defineNuxtModule({
|
|
|
365
365
|
const localeManager = new LocaleManager(options, rootDirs);
|
|
366
366
|
const pageManager = new PageManager(localeManager.locales, options.defaultLocale, options.includeDefaultLocaleRoute);
|
|
367
367
|
nuxt.options.runtimeConfig.public.i18nConfig = {
|
|
368
|
-
rootDir: nuxt.options.rootDir,
|
|
369
|
-
rootDirs,
|
|
370
368
|
plural: options.plural,
|
|
371
369
|
locales: localeManager.locales ?? [],
|
|
372
370
|
meta: options.meta ?? true,
|
|
@@ -382,6 +380,10 @@ const module = defineNuxtModule({
|
|
|
382
380
|
dateBuild: Date.now(),
|
|
383
381
|
baseURL: nuxt.options.app.baseURL
|
|
384
382
|
};
|
|
383
|
+
nuxt.options.runtimeConfig.i18nConfig = {
|
|
384
|
+
rootDir: nuxt.options.rootDir,
|
|
385
|
+
rootDirs
|
|
386
|
+
};
|
|
385
387
|
addPlugin({
|
|
386
388
|
src: resolver.resolve("./runtime/plugins/01.plugin"),
|
|
387
389
|
order: 1
|
|
@@ -426,7 +428,7 @@ const module = defineNuxtModule({
|
|
|
426
428
|
if (!options.disableWatcher) {
|
|
427
429
|
localeManager.ensureTranslationFilesExist(pagesNames, options.translationDir, nuxt.options.rootDir);
|
|
428
430
|
}
|
|
429
|
-
pageManager.extendPages(pages,
|
|
431
|
+
pageManager.extendPages(pages, nuxt.options.rootDir);
|
|
430
432
|
nuxt.options.generate.routes = Array.isArray(nuxt.options.generate.routes) ? nuxt.options.generate.routes : [];
|
|
431
433
|
localeManager.locales.forEach((locale) => {
|
|
432
434
|
if (!options.disablePageLocales) {
|
|
@@ -471,7 +473,7 @@ const module = defineNuxtModule({
|
|
|
471
473
|
const routesSet = prerenderRoutes.routes;
|
|
472
474
|
const additionalRoutes = /* @__PURE__ */ new Set();
|
|
473
475
|
routesSet.forEach((route) => {
|
|
474
|
-
|
|
476
|
+
localeManager.locales.forEach((locale) => {
|
|
475
477
|
if (locale.code !== options.defaultLocale) {
|
|
476
478
|
if (route === "/") {
|
|
477
479
|
additionalRoutes.add(`/${locale.code}`);
|
|
@@ -36,7 +36,7 @@ export default _default;
|
|
|
36
36
|
export interface PluginsInjections {
|
|
37
37
|
$getLocale: () => string;
|
|
38
38
|
$getLocales: () => Locale[];
|
|
39
|
-
$getRouteName: (route?:
|
|
39
|
+
$getRouteName: (route?: RouteLocationRaw, locale?: string) => string;
|
|
40
40
|
$t: <T extends Record<string, string | number | boolean>>(key: string, params?: T, defaultValue?: string) => string | number | boolean | Translations | PluralTranslations | unknown[] | unknown | null;
|
|
41
41
|
$tc: (key: string, count: number, defaultValue?: string) => string;
|
|
42
42
|
$tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
@@ -40,7 +40,7 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale) {
|
|
|
40
40
|
const selectRoute = router.resolve(to);
|
|
41
41
|
const routeName = getRouteName(selectRoute, currentLocale);
|
|
42
42
|
if (router.hasRoute(`localized-${routeName}-${currentLocale}`)) {
|
|
43
|
-
const newParams2 = { ...
|
|
43
|
+
const newParams2 = typeof to === "object" && "params" in to && typeof to.params === "object" ? { ...to.params } : {};
|
|
44
44
|
newParams2.locale = currentLocale;
|
|
45
45
|
return router.resolve({
|
|
46
46
|
params: newParams2,
|
|
@@ -48,7 +48,7 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale) {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
const newRouteName = currentLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute ? `localized-${routeName}` : routeName;
|
|
51
|
-
const newParams = { ...
|
|
51
|
+
const newParams = typeof to === "object" && "params" in to && typeof to.params === "object" ? { ...to.params } : {};
|
|
52
52
|
delete newParams.locale;
|
|
53
53
|
if (currentLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute) {
|
|
54
54
|
newParams.locale = currentLocale;
|
|
@@ -2,11 +2,11 @@ declare const _default: import("#app").Plugin<{
|
|
|
2
2
|
defineI18nRoute: (routeDefinition: {
|
|
3
3
|
locales?: string[] | Record<string, Record<string, string>>;
|
|
4
4
|
localeRoutes?: Record<string, string>;
|
|
5
|
-
}) => Promise<void
|
|
5
|
+
}) => Promise<void>;
|
|
6
6
|
}> & import("#app").ObjectPlugin<{
|
|
7
7
|
defineI18nRoute: (routeDefinition: {
|
|
8
8
|
locales?: string[] | Record<string, Record<string, string>>;
|
|
9
9
|
localeRoutes?: Record<string, string>;
|
|
10
|
-
}) => Promise<void
|
|
10
|
+
}) => Promise<void>;
|
|
11
11
|
}>;
|
|
12
12
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useNuxtApp, useRuntimeConfig } from "#app";
|
|
1
|
+
import { defineNuxtPlugin, navigateTo, useNuxtApp, useRuntimeConfig } from "#app";
|
|
2
2
|
import { useRoute, useRouter } from "#imports";
|
|
3
3
|
export default defineNuxtPlugin((_nuxtApp) => {
|
|
4
4
|
const config = useRuntimeConfig();
|
|
@@ -16,29 +16,32 @@ export default defineNuxtPlugin((_nuxtApp) => {
|
|
|
16
16
|
}
|
|
17
17
|
return {};
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!Object.values(normalizedLocales).length || normalizedLocales[currentLocale]) {
|
|
24
|
-
const translation = normalizedLocales[currentLocale];
|
|
25
|
-
const nuxtApp = useNuxtApp();
|
|
26
|
-
nuxtApp.$mergeTranslations(translation);
|
|
27
|
-
} else {
|
|
19
|
+
useRouter().beforeEach(async (to, from, next) => {
|
|
20
|
+
if (i18nConfig.includeDefaultLocaleRoute) {
|
|
21
|
+
const currentLocale = (to.params.locale || i18nConfig.defaultLocale).toString();
|
|
22
|
+
const { name } = to;
|
|
28
23
|
let defaultRouteName = name?.toString().replace("localized-", "").replace(new RegExp(`-${currentLocale}$`), "");
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (i18nConfig.includeDefaultLocaleRoute) {
|
|
33
|
-
if (router.hasRoute(`localized-${defaultRouteName}-${currentLocale}`)) {
|
|
34
|
-
defaultRouteName = `localized-${defaultRouteName}-${currentLocale}`;
|
|
24
|
+
if (!to.params.locale) {
|
|
25
|
+
if (router.hasRoute(`localized-${to.name?.toString()}-${currentLocale}`)) {
|
|
26
|
+
defaultRouteName = `localized-${to.name?.toString()}-${currentLocale}`;
|
|
35
27
|
} else {
|
|
36
|
-
defaultRouteName = `localized-${
|
|
28
|
+
defaultRouteName = `localized-${to.name?.toString()}`;
|
|
37
29
|
}
|
|
30
|
+
const newParams = { ...to.params };
|
|
38
31
|
newParams.locale = i18nConfig.defaultLocale;
|
|
39
32
|
newParams.name = defaultRouteName;
|
|
33
|
+
await navigateTo({ name: defaultRouteName, params: newParams }, { redirectCode: 301, external: true });
|
|
40
34
|
}
|
|
41
|
-
|
|
35
|
+
}
|
|
36
|
+
next();
|
|
37
|
+
});
|
|
38
|
+
const defineI18nRoute = async (routeDefinition) => {
|
|
39
|
+
const currentLocale = (route.params.locale || i18nConfig.defaultLocale).toString();
|
|
40
|
+
const normalizedLocales = normalizeLocales(routeDefinition.locales);
|
|
41
|
+
if (!Object.values(normalizedLocales).length || normalizedLocales[currentLocale]) {
|
|
42
|
+
const translation = normalizedLocales[currentLocale];
|
|
43
|
+
const nuxtApp = useNuxtApp();
|
|
44
|
+
nuxtApp.$mergeTranslations(translation);
|
|
42
45
|
}
|
|
43
46
|
};
|
|
44
47
|
return {
|
|
@@ -5,7 +5,8 @@ import { useRuntimeConfig } from "#imports";
|
|
|
5
5
|
export default defineEventHandler(async (event) => {
|
|
6
6
|
const { page, locale } = event.context.params;
|
|
7
7
|
const config = useRuntimeConfig();
|
|
8
|
-
const { rootDirs
|
|
8
|
+
const { rootDirs } = config.i18nConfig;
|
|
9
|
+
const { translationDir } = config.public.i18nConfig;
|
|
9
10
|
let path = `${locale}.json`;
|
|
10
11
|
if (page !== "general") {
|
|
11
12
|
path = `pages/${page}/${locale}.json`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.2",
|
|
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":"5b99a708-0632-41fc-89b6-3b4ae1aff60c","timestamp":1725447038241,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|