nuxt-i18n-micro 1.98.0 → 1.99.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/BrUpQP6I.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DGwSTbEi.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C0zq22yw.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1759229335371,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9bdb882b-a145-42be-bbc5-f7c9185266d5",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1759737262750,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"ca54293c-61c3-4dc3-92ac-0c137374a55e",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BrUpQP6I.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DGwSTbEi.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C0zq22yw.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1759229335372,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9bdb882b-a145-42be-bbc5-f7c9185266d5",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1759737262751,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"ca54293c-61c3-4dc3-92ac-0c137374a55e",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -1 +1 @@
1
- {"id":"9bdb882b-a145-42be-bbc5-f7c9185266d5","timestamp":1759229326396}
1
+ {"id":"ca54293c-61c3-4dc3-92ac-0c137374a55e","timestamp":1759737253768}
@@ -0,0 +1 @@
1
+ {"id":"ca54293c-61c3-4dc3-92ac-0c137374a55e","timestamp":1759737253768,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BrUpQP6I.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DGwSTbEi.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C0zq22yw.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1759229335372,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9bdb882b-a145-42be-bbc5-f7c9185266d5",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1759737262751,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"ca54293c-61c3-4dc3-92ac-0c137374a55e",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.98.0",
4
+ "version": "1.99.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -708,7 +708,10 @@ const module = defineNuxtModule({
708
708
  excludePatterns: options.excludePatterns ?? [],
709
709
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
710
710
  // @ts-ignore
711
- routeLocales
711
+ routeLocales,
712
+ experimental: {
713
+ i18nPreviousPageFallback: options.experimental?.i18nPreviousPageFallback ?? false
714
+ }
712
715
  };
713
716
  if (typeof options.customRegexMatcher !== "undefined") {
714
717
  const localeCodes = localeManager.locales.map((l) => l.code);
@@ -31,8 +31,13 @@ export default defineNuxtPlugin(async (nuxtApp) => {
31
31
  );
32
32
  const translationService = new FormatService();
33
33
  const i18nRouteParams = useState("i18n-route-params", () => ({}));
34
- nuxtApp.hook("page:start", () => {
35
- i18nRouteParams.value = null;
34
+ const previousPageInfo = useState("i18n-previous-page", () => null);
35
+ const enablePreviousPageFallback = i18nConfig.experimental?.i18nPreviousPageFallback ?? false;
36
+ nuxtApp.hook("page:finish", () => {
37
+ if (import.meta.client) {
38
+ i18nRouteParams.value = null;
39
+ previousPageInfo.value = null;
40
+ }
36
41
  });
37
42
  const loadTranslationsIfNeeded = async (locale, routeName, path) => {
38
43
  try {
@@ -90,6 +95,12 @@ export default defineNuxtPlugin(async (nuxtApp) => {
90
95
  }
91
96
  router.beforeEach(async (to, from, next) => {
92
97
  if (to.path !== from.path || isNoPrefixStrategy(i18nConfig.strategy)) {
98
+ if (import.meta.client && from.path !== to.path && enablePreviousPageFallback) {
99
+ const fromLocale = routeService.getCurrentLocale(from);
100
+ const fromRouteName = routeService.getRouteName(from, fromLocale);
101
+ previousPageInfo.value = { locale: fromLocale, routeName: fromRouteName };
102
+ console.log(`Saved previous page info for cleanup: ${fromRouteName}`);
103
+ }
93
104
  await loadGlobalTranslations(to);
94
105
  }
95
106
  if (next) {
@@ -115,9 +126,20 @@ export default defineNuxtPlugin(async (nuxtApp) => {
115
126
  const locale = routeService.getCurrentLocale();
116
127
  const routeName = routeService.getRouteName(route, locale);
117
128
  let value = i18nHelper.getTranslation(locale, routeName, key);
129
+ if (!value && previousPageInfo.value && enablePreviousPageFallback) {
130
+ const prev = previousPageInfo.value;
131
+ const prevValue = i18nHelper.getTranslation(prev.locale, prev.routeName, key);
132
+ if (prevValue) {
133
+ value = prevValue;
134
+ console.log(`Using fallback translation from previous route: ${prev.routeName} -> ${key}`);
135
+ }
136
+ }
137
+ if (!value) {
138
+ value = i18nHelper.getTranslation(locale, "", key);
139
+ }
118
140
  if (!value) {
119
141
  if (isDev && import.meta.client) {
120
- console.warn(`Not found '${key}' key in '${locale}' locale messages.`);
142
+ console.warn(`Not found '${key}' key in '${locale}' locale messages for route '${routeName}'.`);
121
143
  }
122
144
  value = defaultValue === void 0 ? key : defaultValue;
123
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.98.0",
3
+ "version": "1.99.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",
@@ -62,7 +62,7 @@
62
62
  "sirv": "^2.0.4",
63
63
  "ufo": "^1.5.4",
64
64
  "nuxt-i18n-micro-core": "1.0.18",
65
- "nuxt-i18n-micro-types": "1.0.8",
65
+ "nuxt-i18n-micro-types": "1.0.9",
66
66
  "nuxt-i18n-micro-test-utils": "1.0.6"
67
67
  },
68
68
  "devDependencies": {
@@ -1 +0,0 @@
1
- {"id":"9bdb882b-a145-42be-bbc5-f7c9185266d5","timestamp":1759229326396,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}