nuxt-i18n-micro 1.70.0 → 1.71.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.
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D5DyI9oC.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.YF1CL0xw.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/I_HlWSXB.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C-ULErdD.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__">[{"prerenderedAt":1,"serverRendered":2},1737549951629,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"adf5f190-89a4-4c2d-abd9-100f4d693fb8",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C-ULErdD.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__">[{"prerenderedAt":1,"serverRendered":2},1737615723489,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"7293fd16-c3d6-456c-a081-94e7b3d79aa9",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D5DyI9oC.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.YF1CL0xw.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/I_HlWSXB.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C-ULErdD.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__">[{"prerenderedAt":1,"serverRendered":2},1737549951630,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"adf5f190-89a4-4c2d-abd9-100f4d693fb8",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C-ULErdD.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__">[{"prerenderedAt":1,"serverRendered":2},1737615723489,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"7293fd16-c3d6-456c-a081-94e7b3d79aa9",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -1 +1 @@
1
- {"id":"adf5f190-89a4-4c2d-abd9-100f4d693fb8","timestamp":1737549945992}
1
+ {"id":"7293fd16-c3d6-456c-a081-94e7b3d79aa9","timestamp":1737615718477}
@@ -0,0 +1 @@
1
+ {"id":"7293fd16-c3d6-456c-a081-94e7b3d79aa9","timestamp":1737615718477,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D5DyI9oC.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.YF1CL0xw.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/I_HlWSXB.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C-ULErdD.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__">[{"prerenderedAt":1,"serverRendered":2},1737549951630,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"adf5f190-89a4-4c2d-abd9-100f4d693fb8",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C-ULErdD.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__">[{"prerenderedAt":1,"serverRendered":2},1737615723489,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"7293fd16-c3d6-456c-a081-94e7b3d79aa9",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
3
  "configKey": "i18n",
4
- "version": "1.70.0",
4
+ "version": "1.71.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -410,6 +410,7 @@ const module = defineNuxtModule({
410
410
  debug: false,
411
411
  define: true,
412
412
  plugin: true,
413
+ hooks: true,
413
414
  types: true,
414
415
  defaultLocale: "en",
415
416
  strategy: "prefix_except_default",
@@ -459,31 +460,21 @@ const module = defineNuxtModule({
459
460
  });
460
461
  const apiBaseUrl = (process.env.NUXT_I18N_APP_BASE_URL ?? options.apiBaseUrl ?? "_locales").replace(/^\/+|\/+$|\/{2,}/, "");
461
462
  nuxt.options.runtimeConfig.public.i18nConfig = {
462
- plural: void 0,
463
463
  locales: localeManager.locales ?? [],
464
- meta: options.meta ?? true,
465
464
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
466
465
  // @ts-ignore
467
466
  metaBaseUrl: options.metaBaseUrl ?? void 0,
468
- define: options.define ?? true,
469
- disableWatcher: options.disableWatcher ?? false,
470
- disableUpdater: options.disableUpdater ?? false,
471
467
  defaultLocale,
472
- translationDir: options.translationDir ?? "locales",
473
468
  localeCookie: options.localeCookie ?? "user-locale",
474
- autoDetectLanguage: options.autoDetectLanguage ?? true,
475
469
  autoDetectPath: options.autoDetectPath ?? "/",
476
470
  strategy: options.strategy ?? "no_prefix",
477
471
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
478
472
  // @ts-ignore
479
473
  routesLocaleLinks: options.routesLocaleLinks ?? {},
480
- fallbackLocale: options.fallbackLocale ?? void 0,
481
474
  dateBuild: Date.now(),
482
475
  hashMode: nuxt.options?.router?.options?.hashMode ?? false,
483
- globalLocaleRoutes: void 0,
484
476
  apiBaseUrl,
485
477
  isSSG,
486
- customRegexMatcher: options.customRegexMatcher,
487
478
  disablePageLocales: options.disablePageLocales ?? false
488
479
  };
489
480
  if (typeof options.customRegexMatcher !== "undefined") {
@@ -495,7 +486,10 @@ const module = defineNuxtModule({
495
486
  nuxt.options.runtimeConfig.i18nConfig = {
496
487
  rootDir: nuxt.options.rootDir,
497
488
  rootDirs,
498
- debug: options.debug ?? false
489
+ debug: options.debug ?? false,
490
+ fallbackLocale: options.fallbackLocale ?? void 0,
491
+ translationDir: options.translationDir ?? "locales",
492
+ customRegexMatcher: options.customRegexMatcher
499
493
  };
500
494
  addImportsDir(resolver.resolve("./runtime/composables"));
501
495
  if (process.env && process.env.TEST) {
@@ -505,6 +499,13 @@ const module = defineNuxtModule({
505
499
  addPlugin({
506
500
  src: resolver.resolve("./runtime/plugins/01.plugin"),
507
501
  name: "i18n-plugin-loader",
502
+ order: -5
503
+ });
504
+ }
505
+ if (options.hooks) {
506
+ addPlugin({
507
+ src: resolver.resolve("./runtime/plugins/05.hooks"),
508
+ name: "i18n-plugin-hooks",
508
509
  order: 1
509
510
  });
510
511
  }
@@ -3,7 +3,7 @@ import type { Locale, I18nRouteParams, Params, Translation, Translations } from
3
3
  declare const _default: import("nuxt/app").Plugin<{
4
4
  i18n: undefined;
5
5
  __micro: boolean;
6
- getLocale: () => string;
6
+ getLocale: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric) => string;
7
7
  getLocaleName: () => string | null;
8
8
  defaultLocale: () => string | undefined;
9
9
  getLocales: () => Locale[];
@@ -27,7 +27,7 @@ declare const _default: import("nuxt/app").Plugin<{
27
27
  }> & import("nuxt/app").ObjectPlugin<{
28
28
  i18n: undefined;
29
29
  __micro: boolean;
30
- getLocale: () => string;
30
+ getLocale: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric) => string;
31
31
  getLocaleName: () => string | null;
32
32
  defaultLocale: () => string | undefined;
33
33
  getLocales: () => Locale[];
@@ -51,7 +51,7 @@ declare const _default: import("nuxt/app").Plugin<{
51
51
  }>;
52
52
  export default _default;
53
53
  export interface PluginsInjections {
54
- $getLocale: () => string;
54
+ $getLocale: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric) => string;
55
55
  $getLocaleName: () => string | null;
56
56
  $getLocales: () => Locale[];
57
57
  $defaultLocale: () => string | undefined;
@@ -85,11 +85,6 @@ export default defineNuxtPlugin(async (nuxtApp) => {
85
85
  const routeName = routeService.getRouteName(to, locale2);
86
86
  await loadTranslationsIfNeeded(locale2, routeName, to.fullPath);
87
87
  }
88
- await nuxtApp.callHook("i18n:register", (translations, selectedLocale) => {
89
- const locale2 = routeService.getCurrentLocale(to);
90
- const routeName = routeService.getRouteName(to, locale2);
91
- i18nHelper.mergeTranslation(selectedLocale ?? locale2, routeName, translations, true);
92
- }, locale);
93
88
  }
94
89
  router.beforeEach(async (to, from, next) => {
95
90
  if (to.path !== from.path || isNoPrefixStrategy(i18nConfig.strategy)) {
@@ -103,7 +98,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
103
98
  const provideData = {
104
99
  i18n: void 0,
105
100
  __micro: true,
106
- getLocale: () => routeService.getCurrentLocale(),
101
+ getLocale: (route) => routeService.getCurrentLocale(route),
107
102
  getLocaleName: () => routeService.getCurrentName(routeService.getCurrentRoute()),
108
103
  defaultLocale: () => i18nConfig.defaultLocale,
109
104
  getLocales: () => i18nConfig.locales || [],
@@ -7,9 +7,6 @@ export default defineNuxtPlugin((nuxtApp) => {
7
7
  const i18nConfig = config.public.i18nConfig;
8
8
  const schema = port === "443" ? "https" : "http";
9
9
  const defaultUrl = port === "80" || port === "443" ? `${schema}://${host}` : `${schema}://${host}:${port}`;
10
- if (!i18nConfig.meta) {
11
- return;
12
- }
13
10
  nuxtApp.hook("app:rendered", (_context) => {
14
11
  const url = useRequestURL();
15
12
  const baseUrl = (i18nConfig.metaBaseUrl || url.origin || defaultUrl).toString();
@@ -1,11 +1,13 @@
1
+ import type { Translations } from 'nuxt-i18n-micro-types';
2
+ type LocalesObject = Record<string, Translations>;
1
3
  declare const _default: import("nuxt/app").Plugin<{
2
4
  defineI18nRoute: (routeDefinition: {
3
- locales?: string[] | Record<string, Record<string, string>>;
5
+ locales?: string[] | LocalesObject;
4
6
  localeRoutes?: Record<string, string>;
5
7
  }) => Promise<void>;
6
8
  }> & import("nuxt/app").ObjectPlugin<{
7
9
  defineI18nRoute: (routeDefinition: {
8
- locales?: string[] | Record<string, Record<string, string>>;
10
+ locales?: string[] | LocalesObject;
9
11
  localeRoutes?: Record<string, string>;
10
12
  }) => Promise<void>;
11
13
  }>;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,26 @@
1
+ import { isNoPrefixStrategy, useTranslationHelper } from "nuxt-i18n-micro-core";
2
+ import { defineNuxtPlugin, useRuntimeConfig } from "#app";
3
+ import { useRouter } from "#imports";
4
+ const i18nHelper = useTranslationHelper();
5
+ export default defineNuxtPlugin(async (nuxtApp) => {
6
+ const config = useRuntimeConfig();
7
+ const i18nConfig = config.public.i18nConfig;
8
+ const router = useRouter();
9
+ const locale = nuxtApp.$getLocale();
10
+ const routeName = nuxtApp.$getRouteName();
11
+ await nuxtApp.callHook("i18n:register", (translations, selectedLocale) => {
12
+ i18nHelper.mergeTranslation(selectedLocale ?? locale, routeName, translations, true);
13
+ }, locale);
14
+ router.beforeEach(async (to, from, next) => {
15
+ if (to.path !== from.path || isNoPrefixStrategy(i18nConfig.strategy)) {
16
+ const locale2 = nuxtApp.$getLocale(to);
17
+ const routeName2 = nuxtApp.$getRouteName(to);
18
+ await nuxtApp.callHook("i18n:register", (translations, selectedLocale) => {
19
+ i18nHelper.mergeTranslation(selectedLocale ?? locale2, routeName2, translations, true);
20
+ }, locale2);
21
+ }
22
+ if (next) {
23
+ next();
24
+ }
25
+ });
26
+ });
@@ -19,8 +19,8 @@ function deepMerge(target, source) {
19
19
  export default defineEventHandler(async (event) => {
20
20
  const { page, locale } = event.context.params;
21
21
  const config = useRuntimeConfig();
22
- const { rootDirs, debug } = config.i18nConfig;
23
- const { translationDir, fallbackLocale, customRegexMatcher, locales } = config.public.i18nConfig;
22
+ const { rootDirs, debug, translationDir, fallbackLocale, customRegexMatcher } = config.i18nConfig;
23
+ const { locales } = config.public.i18nConfig;
24
24
  if (customRegexMatcher && locales && !locales.map((l) => l.code).includes(locale)) {
25
25
  throw createError({ statusCode: 404 });
26
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.70.0",
3
+ "version": "1.71.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",
@@ -53,9 +53,9 @@
53
53
  "globby": "^14.0.2",
54
54
  "sirv": "^2.0.4",
55
55
  "ufo": "^1.5.4",
56
+ "nuxt-i18n-micro-types": "1.0.1",
56
57
  "nuxt-i18n-micro-core": "1.0.15",
57
- "nuxt-i18n-micro-test-utils": "1.0.6",
58
- "nuxt-i18n-micro-types": "1.0.0"
58
+ "nuxt-i18n-micro-test-utils": "1.0.6"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@nuxt/devtools": "^1.7.0",
@@ -1 +0,0 @@
1
- {"id":"adf5f190-89a4-4c2d-abd9-100f4d693fb8","timestamp":1737549945992,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}