nuxt-i18n-micro 1.39.0 → 1.41.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 +9 -9
- package/dist/client/404.html +9 -9
- package/dist/client/_nuxt/{BOuSa-5P.js → -iy35CNe.js} +1 -1
- package/dist/client/_nuxt/DX23HJSw.js +3822 -0
- package/dist/client/_nuxt/{BFMOhgGT.js → EQrrZlvh.js} +1 -1
- package/dist/client/_nuxt/{CKJhJvrR.js → Oli5WrMP.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/eef25448-89f3-4a0c-98a2-c8d49463d371.json +1 -0
- package/dist/client/_nuxt/error-404.BRvVeJss.css +1 -0
- package/dist/client/_nuxt/error-500.DWqKq_Wn.css +1 -0
- package/dist/client/index.html +9 -9
- package/dist/module.d.mts +2 -0
- package/dist/module.d.ts +2 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +39 -20
- package/dist/runtime/components/i18n-link.vue +35 -7
- package/dist/runtime/components/i18n-switcher.vue +4 -3
- package/dist/runtime/composables/useLocaleHead.js +3 -2
- package/dist/runtime/helpers.d.ts +6 -0
- package/dist/runtime/helpers.js +5 -0
- package/dist/runtime/plugins/01.plugin.js +43 -28
- package/dist/runtime/plugins/03.define.js +4 -3
- package/dist/runtime/plugins/04.auto-detect.js +22 -2
- package/package.json +14 -14
- package/dist/client/_nuxt/D9PvWz4w.js +0 -3822
- package/dist/client/_nuxt/builds/meta/b5d51072-a95b-41dc-b6d1-b881701e8826.json +0 -1
- package/dist/client/_nuxt/error-404.D0eU26kO.css +0 -1
- package/dist/client/_nuxt/error-500.CAvb8X3f.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as s,o as a,c as i,a as e,t as o}from"./
|
|
1
|
+
import{_ as s,o as a,c as i,a as e,t as o}from"./DX23HJSw.js";import{u}from"./Oli5WrMP.js";const l={class:"antialiased bg-white dark:bg-black dark:text-white font-sans grid min-h-screen overflow-hidden place-content-center text-black"},c={class:"max-w-520px text-center"},d=["textContent"],p=["textContent"],f={__name:"error-500",props:{appName:{type:String,default:"Nuxt"},version:{type:String,default:""},statusCode:{type:Number,default:500},statusMessage:{type:String,default:"Server error"},description:{type:String,default:"This page is temporarily unavailable."}},setup(t){const r=t;return u({title:`${r.statusCode} - ${r.statusMessage} | ${r.appName}`,script:[{children:`!function(){const e=document.createElement("link").relList;if(!(e&&e.supports&&e.supports("modulepreload"))){for(const e of document.querySelectorAll('link[rel="modulepreload"]'))r(e);new MutationObserver((e=>{for(const o of e)if("childList"===o.type)for(const e of o.addedNodes)"LINK"===e.tagName&&"modulepreload"===e.rel&&r(e)})).observe(document,{childList:!0,subtree:!0})}function r(e){if(e.ep)return;e.ep=!0;const r=function(e){const r={};return e.integrity&&(r.integrity=e.integrity),e.referrerPolicy&&(r.referrerPolicy=e.referrerPolicy),"use-credentials"===e.crossOrigin?r.credentials="include":"anonymous"===e.crossOrigin?r.credentials="omit":r.credentials="same-origin",r}(e);fetch(e.href,r)}}();`}],style:[{children:'*,:after,:before{border-color:var(--un-default-border-color,#e5e7eb);border-style:solid;border-width:0;box-sizing:border-box}:after,:before{--un-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal;-moz-tab-size:4;tab-size:4;-webkit-tap-highlight-color:transparent}body{line-height:inherit;margin:0}h1{font-size:inherit;font-weight:inherit}h1,p{margin:0}*,:after,:before{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 transparent;--un-ring-shadow:0 0 transparent;--un-shadow-inset: ;--un-shadow:0 0 transparent;--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgba(147,197,253,.5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }'}]}),(g,n)=>(a(),i("div",l,[n[0]||(n[0]=e("div",{class:"-bottom-1/2 fixed h-1/2 left-0 right-0 spotlight"},null,-1)),e("div",c,[e("h1",{class:"font-medium mb-8 sm:text-10xl text-8xl",textContent:o(t.statusCode)},null,8,d),e("p",{class:"font-light leading-tight mb-16 px-8 sm:px-0 sm:text-4xl text-xl",textContent:o(t.description)},null,8,p)])]))}},b=s(f,[["__scopeId","data-v-e19fb17d"]]);export{b as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as f,r as u,f as o,g as d,h as v,j as l,k as i,l as h,m}from"./
|
|
1
|
+
import{i as f,r as u,f as o,g as d,h as v,j as l,k as i,l as h,m}from"./DX23HJSw.js";function U(t,a={}){const e=a.head||f();if(e)return e.ssr?e.push(t,a):p(e,t,a)}function p(t,a,e={}){const s=u(!1),n=u({});o(()=>{n.value=s.value?{}:d(a)});const r=t.push(n.value,e);return v(n,c=>{r.patch(c)}),m()&&(l(()=>{r.dispose()}),i(()=>{s.value=!0}),h(()=>{s.value=!1})),r}export{U as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"eef25448-89f3-4a0c-98a2-c8d49463d371","timestamp":1734683108217}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"eef25448-89f3-4a0c-98a2-c8d49463d371","timestamp":1734683108217,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.spotlight[data-v-ccc980e5]{background:linear-gradient(45deg,#00dc82,#36e4da 50%,#0047e1);bottom:-30vh;filter:blur(20vh);height:40vh}.gradient-border[data-v-ccc980e5]{-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);border-radius:.5rem;position:relative}@media (prefers-color-scheme:light){.gradient-border[data-v-ccc980e5]{background-color:#ffffff4d}.gradient-border[data-v-ccc980e5]:before{background:linear-gradient(90deg,#e2e2e2,#e2e2e2 25%,#00dc82,#36e4da 75%,#0047e1)}}@media (prefers-color-scheme:dark){.gradient-border[data-v-ccc980e5]{background-color:#1414144d}.gradient-border[data-v-ccc980e5]:before{background:linear-gradient(90deg,#303030,#303030 25%,#00dc82,#36e4da 75%,#0047e1)}}.gradient-border[data-v-ccc980e5]:before{background-size:400% auto;border-radius:.5rem;bottom:0;content:"";left:0;-webkit-mask:linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0);mask:linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0);-webkit-mask-composite:xor;mask-composite:exclude;opacity:.5;padding:2px;position:absolute;right:0;top:0;transition:background-position .3s ease-in-out,opacity .2s ease-in-out;width:100%}.gradient-border[data-v-ccc980e5]:hover:before{background-position:-50% 0;opacity:1}.fixed[data-v-ccc980e5]{position:fixed}.left-0[data-v-ccc980e5]{left:0}.right-0[data-v-ccc980e5]{right:0}.z-10[data-v-ccc980e5]{z-index:10}.z-20[data-v-ccc980e5]{z-index:20}.grid[data-v-ccc980e5]{display:grid}.mb-16[data-v-ccc980e5]{margin-bottom:4rem}.mb-8[data-v-ccc980e5]{margin-bottom:2rem}.max-w-520px[data-v-ccc980e5]{max-width:520px}.min-h-screen[data-v-ccc980e5]{min-height:100vh}.w-full[data-v-ccc980e5]{width:100%}.flex[data-v-ccc980e5]{display:flex}.cursor-pointer[data-v-ccc980e5]{cursor:pointer}.place-content-center[data-v-ccc980e5]{place-content:center}.items-center[data-v-ccc980e5]{align-items:center}.justify-center[data-v-ccc980e5]{justify-content:center}.overflow-hidden[data-v-ccc980e5]{overflow:hidden}.bg-white[data-v-ccc980e5]{--un-bg-opacity:1;background-color:rgb(255 255 255/var(--un-bg-opacity))}.px-4[data-v-ccc980e5]{padding-left:1rem;padding-right:1rem}.px-8[data-v-ccc980e5]{padding-left:2rem;padding-right:2rem}.py-2[data-v-ccc980e5]{padding-bottom:.5rem;padding-top:.5rem}.text-center[data-v-ccc980e5]{text-align:center}.text-8xl[data-v-ccc980e5]{font-size:6rem;line-height:1}.text-xl[data-v-ccc980e5]{font-size:1.25rem;line-height:1.75rem}.text-black[data-v-ccc980e5]{--un-text-opacity:1;color:rgb(0 0 0/var(--un-text-opacity))}.font-light[data-v-ccc980e5]{font-weight:300}.font-medium[data-v-ccc980e5]{font-weight:500}.leading-tight[data-v-ccc980e5]{line-height:1.25}.font-sans[data-v-ccc980e5]{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.antialiased[data-v-ccc980e5]{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}@media (prefers-color-scheme:dark){.dark\:bg-black[data-v-ccc980e5]{--un-bg-opacity:1;background-color:rgb(0 0 0/var(--un-bg-opacity))}.dark\:text-white[data-v-ccc980e5]{--un-text-opacity:1;color:rgb(255 255 255/var(--un-text-opacity))}}@media (min-width:640px){.sm\:px-0[data-v-ccc980e5]{padding-left:0;padding-right:0}.sm\:px-6[data-v-ccc980e5]{padding-left:1.5rem;padding-right:1.5rem}.sm\:py-3[data-v-ccc980e5]{padding-bottom:.75rem;padding-top:.75rem}.sm\:text-4xl[data-v-ccc980e5]{font-size:2.25rem;line-height:2.5rem}.sm\:text-xl[data-v-ccc980e5]{font-size:1.25rem;line-height:1.75rem}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.spotlight[data-v-e19fb17d]{background:linear-gradient(45deg,#00dc82,#36e4da 50%,#0047e1);filter:blur(20vh)}.fixed[data-v-e19fb17d]{position:fixed}.-bottom-1\/2[data-v-e19fb17d]{bottom:-50%}.left-0[data-v-e19fb17d]{left:0}.right-0[data-v-e19fb17d]{right:0}.grid[data-v-e19fb17d]{display:grid}.mb-16[data-v-e19fb17d]{margin-bottom:4rem}.mb-8[data-v-e19fb17d]{margin-bottom:2rem}.h-1\/2[data-v-e19fb17d]{height:50%}.max-w-520px[data-v-e19fb17d]{max-width:520px}.min-h-screen[data-v-e19fb17d]{min-height:100vh}.place-content-center[data-v-e19fb17d]{place-content:center}.overflow-hidden[data-v-e19fb17d]{overflow:hidden}.bg-white[data-v-e19fb17d]{--un-bg-opacity:1;background-color:rgb(255 255 255/var(--un-bg-opacity))}.px-8[data-v-e19fb17d]{padding-left:2rem;padding-right:2rem}.text-center[data-v-e19fb17d]{text-align:center}.text-8xl[data-v-e19fb17d]{font-size:6rem;line-height:1}.text-xl[data-v-e19fb17d]{font-size:1.25rem;line-height:1.75rem}.text-black[data-v-e19fb17d]{--un-text-opacity:1;color:rgb(0 0 0/var(--un-text-opacity))}.font-light[data-v-e19fb17d]{font-weight:300}.font-medium[data-v-e19fb17d]{font-weight:500}.leading-tight[data-v-e19fb17d]{line-height:1.25}.font-sans[data-v-e19fb17d]{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.antialiased[data-v-e19fb17d]{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}@media (prefers-color-scheme:dark){.dark\:bg-black[data-v-e19fb17d]{--un-bg-opacity:1;background-color:rgb(0 0 0/var(--un-bg-opacity))}.dark\:text-white[data-v-e19fb17d]{--un-text-opacity:1;color:rgb(255 255 255/var(--un-text-opacity))}}@media (min-width:640px){.sm\:px-0[data-v-e19fb17d]{padding-left:0;padding-right:0}.sm\:text-4xl[data-v-e19fb17d]{font-size:2.25rem;line-height:2.5rem}}
|
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
|
-
<link rel="stylesheet" href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/entry.B5pGkSSX.css"
|
|
4
|
-
<link rel="modulepreload" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/
|
|
3
|
+
<link rel="stylesheet" href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/entry.B5pGkSSX.css">
|
|
4
|
+
<link rel="modulepreload" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/DX23HJSw.js">
|
|
5
5
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/B6E6ObS_.js">
|
|
6
|
-
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-404.
|
|
7
|
-
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt
|
|
8
|
-
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/
|
|
9
|
-
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.
|
|
10
|
-
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
6
|
+
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-404.BRvVeJss.css">
|
|
7
|
+
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/-iy35CNe.js">
|
|
8
|
+
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Oli5WrMP.js">
|
|
9
|
+
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DWqKq_Wn.css">
|
|
10
|
+
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/EQrrZlvh.js">
|
|
11
|
+
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/DX23HJSw.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},1734683114599,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"eef25448-89f3-4a0c-98a2-c8d49463d371",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.d.mts
CHANGED
|
@@ -16,9 +16,11 @@ type Params = Record<string, string | number | boolean>;
|
|
|
16
16
|
type Getter = (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
|
|
17
17
|
type PluralFunc = (key: string, count: number, params: Params, locale: string, getter: Getter) => string | null;
|
|
18
18
|
type GlobalLocaleRoutes = Record<string, Record<LocaleCode, string> | false | boolean> | null | undefined;
|
|
19
|
+
type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default';
|
|
19
20
|
interface ModuleOptions {
|
|
20
21
|
locales?: Locale[];
|
|
21
22
|
meta?: boolean;
|
|
23
|
+
strategy?: Strategies;
|
|
22
24
|
metaBaseUrl?: string;
|
|
23
25
|
define?: boolean;
|
|
24
26
|
defaultLocale?: string;
|
package/dist/module.d.ts
CHANGED
|
@@ -16,9 +16,11 @@ type Params = Record<string, string | number | boolean>;
|
|
|
16
16
|
type Getter = (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
|
|
17
17
|
type PluralFunc = (key: string, count: number, params: Params, locale: string, getter: Getter) => string | null;
|
|
18
18
|
type GlobalLocaleRoutes = Record<string, Record<LocaleCode, string> | false | boolean> | null | undefined;
|
|
19
|
+
type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default';
|
|
19
20
|
interface ModuleOptions {
|
|
20
21
|
locales?: Locale[];
|
|
21
22
|
meta?: boolean;
|
|
23
|
+
strategy?: Strategies;
|
|
22
24
|
metaBaseUrl?: string;
|
|
23
25
|
define?: boolean;
|
|
24
26
|
defaultLocale?: string;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { watch } from 'chokidar';
|
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
|
|
8
8
|
import sirv from 'sirv';
|
|
9
|
+
import { isPrefixAndDefaultStrategy, isPrefixStrategy, isNoPrefixStrategy, withPrefixStrategy } from '../dist/runtime/helpers.js';
|
|
9
10
|
|
|
10
11
|
const DEVTOOLS_UI_PORT = 3030;
|
|
11
12
|
const DEVTOOLS_UI_ROUTE = "/__nuxt-i18n-micro";
|
|
@@ -172,14 +173,14 @@ const buildRouteNameFromRoute = (name, path2) => {
|
|
|
172
173
|
class PageManager {
|
|
173
174
|
locales;
|
|
174
175
|
defaultLocale;
|
|
175
|
-
|
|
176
|
+
strategy;
|
|
176
177
|
localizedPaths = {};
|
|
177
178
|
activeLocaleCodes;
|
|
178
179
|
globalLocaleRoutes;
|
|
179
|
-
constructor(locales, defaultLocaleCode,
|
|
180
|
+
constructor(locales, defaultLocaleCode, strategy, globalLocaleRoutes) {
|
|
180
181
|
this.locales = locales;
|
|
181
182
|
this.defaultLocale = this.findLocaleByCode(defaultLocaleCode) || { code: defaultLocaleCode };
|
|
182
|
-
this.
|
|
183
|
+
this.strategy = strategy;
|
|
183
184
|
this.activeLocaleCodes = this.computeActiveLocaleCodes();
|
|
184
185
|
this.globalLocaleRoutes = globalLocaleRoutes || {};
|
|
185
186
|
}
|
|
@@ -187,7 +188,7 @@ class PageManager {
|
|
|
187
188
|
return this.locales.find((locale) => locale.code === code);
|
|
188
189
|
}
|
|
189
190
|
computeActiveLocaleCodes() {
|
|
190
|
-
return this.locales.filter((locale) => locale.code !== this.defaultLocale.code || this.
|
|
191
|
+
return this.locales.filter((locale) => locale.code !== this.defaultLocale.code || isPrefixAndDefaultStrategy(this.strategy) || isPrefixStrategy(this.strategy)).map((locale) => locale.code);
|
|
191
192
|
}
|
|
192
193
|
extendPages(pages, rootDir, customRegex, isCloudflarePages) {
|
|
193
194
|
this.localizedPaths = this.extractLocalizedPaths(pages, rootDir);
|
|
@@ -206,7 +207,7 @@ class PageManager {
|
|
|
206
207
|
this.localizePage(page, additionalRoutes, customRegex);
|
|
207
208
|
}
|
|
208
209
|
});
|
|
209
|
-
if (this.
|
|
210
|
+
if (isPrefixStrategy(this.strategy) && !isCloudflarePages) {
|
|
210
211
|
for (let i = pages.length - 1; i >= 0; i--) {
|
|
211
212
|
const page = pages[i];
|
|
212
213
|
const pagePath = page.path ?? "";
|
|
@@ -251,12 +252,15 @@ class PageManager {
|
|
|
251
252
|
const customPath = customRoutePaths[locale.code];
|
|
252
253
|
if (!customPath)
|
|
253
254
|
return;
|
|
254
|
-
const isDefaultLocale = isLocaleDefault(locale, this.defaultLocale, this.
|
|
255
|
+
const isDefaultLocale = isLocaleDefault(locale, this.defaultLocale, isPrefixStrategy(this.strategy));
|
|
255
256
|
if (isDefaultLocale) {
|
|
256
257
|
page.path = normalizePath(customPath);
|
|
257
258
|
} else {
|
|
258
259
|
additionalRoutes.push(this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex));
|
|
259
260
|
}
|
|
261
|
+
if (isPrefixAndDefaultStrategy(this.strategy) && locale === this.defaultLocale) {
|
|
262
|
+
additionalRoutes.push(this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex, true));
|
|
263
|
+
}
|
|
260
264
|
});
|
|
261
265
|
}
|
|
262
266
|
localizePage(page, additionalRoutes, customRegex) {
|
|
@@ -306,12 +310,15 @@ class PageManager {
|
|
|
306
310
|
const customPath = this.localizedPaths[fullPath]?.[locale.code];
|
|
307
311
|
if (!customPath)
|
|
308
312
|
return;
|
|
309
|
-
const isDefaultLocale = isLocaleDefault(locale, this.defaultLocale, this.
|
|
313
|
+
const isDefaultLocale = isLocaleDefault(locale, this.defaultLocale, isPrefixStrategy(this.strategy));
|
|
310
314
|
if (isDefaultLocale) {
|
|
311
315
|
page.children = this.createLocalizedChildren(originalChildren, "", [locale.code], false);
|
|
312
316
|
} else {
|
|
313
317
|
additionalRoutes.push(this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex));
|
|
314
318
|
}
|
|
319
|
+
if (isPrefixAndDefaultStrategy(this.strategy) && locale === this.defaultLocale) {
|
|
320
|
+
additionalRoutes.push(this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex, true));
|
|
321
|
+
}
|
|
315
322
|
});
|
|
316
323
|
}
|
|
317
324
|
createLocalizedChildren(routes, parentPath, localeCodes, modifyName = true, addLocalePrefix = false) {
|
|
@@ -324,8 +331,8 @@ class PageManager {
|
|
|
324
331
|
const localizedChildren = this.createLocalizedChildren(route.children ?? [], fullPath, localeCodes, modifyName);
|
|
325
332
|
return localeCodes.map((locale) => this.createLocalizedChildRoute(route, routePath, locale, customLocalePaths, localizedChildren, modifyName, addLocalePrefix));
|
|
326
333
|
}
|
|
327
|
-
createLocalizedRoute(page, localeCodes, originalChildren, isCustom, customPath = "", customRegex) {
|
|
328
|
-
const routePath = this.buildRoutePath(localeCodes, page.path, encodeURI(customPath), isCustom, customRegex);
|
|
334
|
+
createLocalizedRoute(page, localeCodes, originalChildren, isCustom, customPath = "", customRegex, force = false) {
|
|
335
|
+
const routePath = this.buildRoutePath(localeCodes, page.path, encodeURI(customPath), isCustom, customRegex, force);
|
|
329
336
|
const routeName = buildRouteName(buildRouteNameFromRoute(page.name, page.path), localeCodes[0], isCustom);
|
|
330
337
|
return {
|
|
331
338
|
...page,
|
|
@@ -347,14 +354,14 @@ class PageManager {
|
|
|
347
354
|
buildLocalizedRoutePath(routePath, locale, customLocalePaths, addLocalePrefix) {
|
|
348
355
|
const basePath = customLocalePaths?.[locale] || routePath;
|
|
349
356
|
const normalizedBasePath = encodeURI(normalizePath(basePath));
|
|
350
|
-
return shouldAddLocalePrefix(locale, this.defaultLocale, addLocalePrefix, this.
|
|
357
|
+
return shouldAddLocalePrefix(locale, this.defaultLocale, addLocalePrefix, isPrefixStrategy(this.strategy)) ? buildFullPath(locale, normalizedBasePath) : normalizedBasePath;
|
|
351
358
|
}
|
|
352
359
|
buildLocalizedRouteName(baseName, locale, modifyName) {
|
|
353
|
-
return modifyName && !isLocaleDefault(locale, this.defaultLocale, this.
|
|
360
|
+
return modifyName && !isLocaleDefault(locale, this.defaultLocale, isPrefixStrategy(this.strategy) || isPrefixAndDefaultStrategy(this.strategy)) ? `localized-${baseName}-${locale}` : baseName;
|
|
354
361
|
}
|
|
355
|
-
buildRoutePath(localeCodes, originalPath, customPath, isCustom, customRegex) {
|
|
362
|
+
buildRoutePath(localeCodes, originalPath, customPath, isCustom, customRegex, force = false) {
|
|
356
363
|
if (isCustom) {
|
|
357
|
-
return this.
|
|
364
|
+
return force || isPrefixStrategy(this.strategy) || !localeCodes.includes(this.defaultLocale.code) ? buildFullPath(localeCodes, customPath, customRegex) : normalizePath(customPath);
|
|
358
365
|
}
|
|
359
366
|
return buildFullPath(localeCodes, originalPath, customRegex);
|
|
360
367
|
}
|
|
@@ -437,12 +444,13 @@ const module = defineNuxtModule({
|
|
|
437
444
|
define: true,
|
|
438
445
|
types: true,
|
|
439
446
|
defaultLocale: "en",
|
|
447
|
+
strategy: "prefix_except_default",
|
|
440
448
|
translationDir: "locales",
|
|
441
449
|
autoDetectPath: "/",
|
|
442
450
|
autoDetectLanguage: true,
|
|
443
451
|
disablePageLocales: false,
|
|
444
452
|
disableWatcher: false,
|
|
445
|
-
includeDefaultLocaleRoute:
|
|
453
|
+
includeDefaultLocaleRoute: void 0,
|
|
446
454
|
fallbackLocale: void 0,
|
|
447
455
|
localeCookie: "user-locale",
|
|
448
456
|
apiBaseUrl: "_locales",
|
|
@@ -461,10 +469,18 @@ const module = defineNuxtModule({
|
|
|
461
469
|
async setup(options, nuxt) {
|
|
462
470
|
const isSSG = nuxt.options._generate;
|
|
463
471
|
const isCloudflarePages = nuxt.options.nitro.preset === "cloudflare_pages" || process.env.NITRO_PRESET === "cloudflare-pages";
|
|
464
|
-
|
|
472
|
+
const logger = useLogger("nuxt-i18n-micro");
|
|
473
|
+
if (options.includeDefaultLocaleRoute !== void 0) {
|
|
474
|
+
logger.debug("The 'includeDefaultLocaleRoute' option is deprecated. Use 'strategy' instead.");
|
|
475
|
+
if (options.includeDefaultLocaleRoute) {
|
|
476
|
+
options.strategy = "prefix";
|
|
477
|
+
} else {
|
|
478
|
+
options.strategy = "prefix_except_default";
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if (isCloudflarePages && !isPrefixStrategy(options.strategy)) {
|
|
465
482
|
throw new Error('Nuxt-i18n-micro: "includeDefaultLocaleRoute" must be set to true when using Cloudflare Pages.');
|
|
466
483
|
}
|
|
467
|
-
const logger = useLogger("nuxt-i18n-micro");
|
|
468
484
|
try {
|
|
469
485
|
const storagePahh = path.join(nuxt.options.rootDir, "./server/assets");
|
|
470
486
|
fs__default.rmdirSync(storagePahh);
|
|
@@ -474,7 +490,7 @@ const module = defineNuxtModule({
|
|
|
474
490
|
const resolver = createResolver(import.meta.url);
|
|
475
491
|
const rootDirs = nuxt.options._layers.map((layer) => layer.config.rootDir).reverse();
|
|
476
492
|
const localeManager = new LocaleManager(options, rootDirs);
|
|
477
|
-
const pageManager = new PageManager(localeManager.locales, options.defaultLocale, options.
|
|
493
|
+
const pageManager = new PageManager(localeManager.locales, options.defaultLocale, options.strategy, options.globalLocaleRoutes);
|
|
478
494
|
addTemplate({
|
|
479
495
|
filename: "i18n.plural.mjs",
|
|
480
496
|
write: true,
|
|
@@ -493,7 +509,7 @@ const module = defineNuxtModule({
|
|
|
493
509
|
localeCookie: options.localeCookie ?? "user-locale",
|
|
494
510
|
autoDetectLanguage: options.autoDetectLanguage ?? true,
|
|
495
511
|
autoDetectPath: options.autoDetectPath ?? "/",
|
|
496
|
-
|
|
512
|
+
strategy: options.strategy ?? "no_prefix",
|
|
497
513
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
498
514
|
// @ts-ignore
|
|
499
515
|
routesLocaleLinks: options.routesLocaleLinks ?? {},
|
|
@@ -564,12 +580,15 @@ const module = defineNuxtModule({
|
|
|
564
580
|
});
|
|
565
581
|
}
|
|
566
582
|
extendPages((pages) => {
|
|
583
|
+
if (isNoPrefixStrategy(options.strategy)) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
567
586
|
const pagesNames = pages.map((page) => page.name).filter((name) => name !== void 0 && (!options.routesLocaleLinks || !options.routesLocaleLinks[name]));
|
|
568
587
|
if (!options.disableWatcher) {
|
|
569
588
|
localeManager.ensureTranslationFilesExist(pagesNames, options.translationDir, nuxt.options.rootDir);
|
|
570
589
|
}
|
|
571
590
|
pageManager.extendPages(pages, nuxt.options.rootDir, options.customRegexMatcher, isCloudflarePages);
|
|
572
|
-
if (options.
|
|
591
|
+
if (isPrefixStrategy(options.strategy) && !isCloudflarePages) {
|
|
573
592
|
const fallbackRoute = {
|
|
574
593
|
path: "/:pathMatch(.*)*",
|
|
575
594
|
name: "custom-fallback-route",
|
|
@@ -631,7 +650,7 @@ const module = defineNuxtModule({
|
|
|
631
650
|
nuxt.options.generate.routes = Array.isArray(nuxt.options.generate.routes) ? nuxt.options.generate.routes : [];
|
|
632
651
|
const pages = nuxt.options.generate.routes || [];
|
|
633
652
|
localeManager.locales.forEach((locale) => {
|
|
634
|
-
if (locale.code !== options.defaultLocale || options.
|
|
653
|
+
if (locale.code !== options.defaultLocale || withPrefixStrategy(options.strategy)) {
|
|
635
654
|
pages.forEach((page) => {
|
|
636
655
|
if (!/\.[a-z0-9]+$/i.test(page)) {
|
|
637
656
|
routes.push(`/${locale.code}${page}`);
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
<template>
|
|
2
|
+
<a
|
|
3
|
+
v-if="isExternalLink"
|
|
4
|
+
:href="externalHref"
|
|
5
|
+
:style="computedStyle"
|
|
6
|
+
target="_blank"
|
|
7
|
+
rel="noopener noreferrer"
|
|
8
|
+
>
|
|
9
|
+
<slot />
|
|
10
|
+
</a>
|
|
11
|
+
|
|
2
12
|
<NuxtLink
|
|
13
|
+
v-else
|
|
3
14
|
:to="$localeRoute(to)"
|
|
4
|
-
:style="
|
|
15
|
+
:style="computedStyle"
|
|
5
16
|
>
|
|
6
17
|
<slot />
|
|
7
18
|
</NuxtLink>
|
|
@@ -17,13 +28,33 @@ const { $localeRoute } = useNuxtApp()
|
|
|
17
28
|
|
|
18
29
|
interface Props {
|
|
19
30
|
to: RouteLocationRaw | string
|
|
20
|
-
activeStyle?: Partial<
|
|
31
|
+
activeStyle?: Partial<CSSStyleValue>
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
const props = defineProps<Props>()
|
|
24
35
|
const route = useRoute()
|
|
25
36
|
|
|
37
|
+
const isExternalLink = computed(() => {
|
|
38
|
+
if (typeof props.to === 'string') {
|
|
39
|
+
return /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})/.test(props.to)
|
|
40
|
+
}
|
|
41
|
+
return false
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const externalHref = computed(() => {
|
|
45
|
+
if (isExternalLink.value && typeof props.to === 'string') {
|
|
46
|
+
if (!/^https?:\/\//.test(props.to)) {
|
|
47
|
+
return `https://${props.to}`
|
|
48
|
+
}
|
|
49
|
+
return props.to
|
|
50
|
+
}
|
|
51
|
+
return undefined
|
|
52
|
+
})
|
|
53
|
+
|
|
26
54
|
const isActive = computed(() => {
|
|
55
|
+
if (isExternalLink.value) {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
27
58
|
// If `to` is a string, compare it directly to the route path
|
|
28
59
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
29
60
|
// @ts-ignore
|
|
@@ -35,12 +66,9 @@ const isActive = computed(() => {
|
|
|
35
66
|
return route.path === newPath.path
|
|
36
67
|
})
|
|
37
68
|
|
|
38
|
-
|
|
39
|
-
const activeStyle = computed(() => {
|
|
69
|
+
const computedStyle = computed((): Partial<CSSStyleValue> => {
|
|
40
70
|
return isActive.value
|
|
41
|
-
? {
|
|
42
|
-
...props.activeStyle, // Merge with any custom active styles passed as props
|
|
43
|
-
}
|
|
71
|
+
? { ...props.activeStyle }
|
|
44
72
|
: {}
|
|
45
73
|
})
|
|
46
74
|
</script>
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
customLinkStyle,
|
|
42
42
|
]"
|
|
43
43
|
:hreflang="locale.iso || locale.code"
|
|
44
|
-
@click="switchLocale()"
|
|
44
|
+
@click="switchLocale(locale.code)"
|
|
45
45
|
>
|
|
46
46
|
<slot
|
|
47
47
|
name="before-link-content"
|
|
@@ -107,7 +107,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
107
107
|
customIconStyle: () => ({}),
|
|
108
108
|
})
|
|
109
109
|
|
|
110
|
-
const { $switchLocaleRoute, $getLocales, $getLocale, $getLocaleName } = useNuxtApp()
|
|
110
|
+
const { $switchLocaleRoute, $switchLocale, $getLocales, $getLocale, $getLocaleName } = useNuxtApp()
|
|
111
111
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
112
112
|
// @ts-ignore
|
|
113
113
|
const locales = ref($getLocales())
|
|
@@ -144,8 +144,9 @@ const currentLocaleLabel = computed(() => localeLabel({
|
|
|
144
144
|
displayName: currentLocaleName.value ?? undefined,
|
|
145
145
|
}))
|
|
146
146
|
|
|
147
|
-
const switchLocale = () => {
|
|
147
|
+
const switchLocale = (code: string) => {
|
|
148
148
|
toggleDropdown()
|
|
149
|
+
$switchLocale(code)
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
// Default Styles
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { joinURL } from "ufo";
|
|
2
|
+
import { isPrefixExceptDefaultStrategy } from "../helpers.js";
|
|
2
3
|
import { unref, useRoute, useRuntimeConfig, watch, onUnmounted, ref, useNuxtApp } from "#imports";
|
|
3
4
|
export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "id", addSeoAttributes = true, baseUrl = "/" } = {}) => {
|
|
4
5
|
const metaObject = ref({
|
|
@@ -7,7 +8,7 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
7
8
|
meta: []
|
|
8
9
|
});
|
|
9
10
|
function updateMeta() {
|
|
10
|
-
const { defaultLocale,
|
|
11
|
+
const { defaultLocale, strategy } = useRuntimeConfig().public.i18nConfig;
|
|
11
12
|
const { $getLocales, $getLocale } = useNuxtApp();
|
|
12
13
|
const route = useRoute();
|
|
13
14
|
const locale = unref($getLocale());
|
|
@@ -62,7 +63,7 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
62
63
|
href: ogUrl
|
|
63
64
|
};
|
|
64
65
|
const alternateLinks = alternateLocales.flatMap((loc) => {
|
|
65
|
-
const href = defaultLocale === loc.code &&
|
|
66
|
+
const href = defaultLocale === loc.code && isPrefixExceptDefaultStrategy(strategy) ? indexUrl : joinURL(unref(baseUrl), loc.code, fullPath);
|
|
66
67
|
const links = [{
|
|
67
68
|
[identifierAttribute]: `i18n-alternate-${loc.code}`,
|
|
68
69
|
rel: "alternate",
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Strategies } from '../types.js';
|
|
2
|
+
export declare const withPrefixStrategy: (strategy: Strategies) => strategy is "prefix" | "prefix_and_default";
|
|
3
|
+
export declare const isNoPrefixStrategy: (strategy: Strategies) => strategy is "no_prefix";
|
|
4
|
+
export declare const isPrefixStrategy: (strategy: Strategies) => strategy is "prefix";
|
|
5
|
+
export declare const isPrefixExceptDefaultStrategy: (strategy: Strategies) => strategy is "prefix_except_default";
|
|
6
|
+
export declare const isPrefixAndDefaultStrategy: (strategy: Strategies) => strategy is "prefix_and_default";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const withPrefixStrategy = (strategy) => strategy === "prefix" || strategy === "prefix_and_default";
|
|
2
|
+
export const isNoPrefixStrategy = (strategy) => strategy === "no_prefix";
|
|
3
|
+
export const isPrefixStrategy = (strategy) => strategy === "prefix";
|
|
4
|
+
export const isPrefixExceptDefaultStrategy = (strategy) => strategy === "prefix_except_default";
|
|
5
|
+
export const isPrefixAndDefaultStrategy = (strategy) => strategy === "prefix_and_default";
|