nuxt-i18n-micro 1.40.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-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/4316af1d-27df-4ab9-b027-2c99cf42eaf5.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}`);
|
|
@@ -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";
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { useTranslationHelper, interpolate } from "nuxt-i18n-micro-core";
|
|
2
|
+
import { isNoPrefixStrategy, withPrefixStrategy } from "../helpers.js";
|
|
2
3
|
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
3
4
|
import { useRouter, useCookie, useState, navigateTo } from "#imports";
|
|
4
5
|
import { plural } from "#build/i18n.plural.mjs";
|
|
5
6
|
const i18nHelper = useTranslationHelper();
|
|
6
7
|
const isDev = process.env.NODE_ENV !== "production";
|
|
7
|
-
function getCurrentLocale(route, i18nConfig, hashLocale) {
|
|
8
|
+
function getCurrentLocale(route, i18nConfig, hashLocale, noPrefixStrategy) {
|
|
8
9
|
if (i18nConfig.hashMode && hashLocale) {
|
|
9
10
|
return hashLocale;
|
|
10
11
|
}
|
|
12
|
+
if (isNoPrefixStrategy(i18nConfig.strategy) && noPrefixStrategy) {
|
|
13
|
+
return noPrefixStrategy;
|
|
14
|
+
}
|
|
11
15
|
return (route.params?.locale ?? i18nConfig.defaultLocale).toString();
|
|
12
16
|
}
|
|
13
|
-
function getCurrentName(route, i18nConfig, hashLocale) {
|
|
14
|
-
const currentLocaleCode = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
17
|
+
function getCurrentName(route, i18nConfig, hashLocale, noPrefixStrategy) {
|
|
18
|
+
const currentLocaleCode = getCurrentLocale(route, i18nConfig, hashLocale, noPrefixStrategy);
|
|
15
19
|
const checkLocale = i18nConfig.locales?.find((l) => l.code === currentLocaleCode);
|
|
16
20
|
if (!checkLocale) {
|
|
17
21
|
return null;
|
|
@@ -52,11 +56,14 @@ function switchLocaleRoute(fromLocale, toLocale, route, router, i18nConfig, i18n
|
|
|
52
56
|
}
|
|
53
57
|
return newRoute2;
|
|
54
58
|
}
|
|
55
|
-
|
|
59
|
+
let newRouteName = routeName;
|
|
56
60
|
const newParams = { ...route.params, ...i18nRouteParams?.[toLocale] };
|
|
57
61
|
delete newParams.locale;
|
|
58
|
-
if (
|
|
59
|
-
|
|
62
|
+
if (!isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
63
|
+
newRouteName = toLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy) ? `localized-${routeName}` : routeName;
|
|
64
|
+
if (toLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy)) {
|
|
65
|
+
newParams.locale = toLocale;
|
|
66
|
+
}
|
|
60
67
|
}
|
|
61
68
|
if (i18nConfig.hashMode) {
|
|
62
69
|
const userLocaleCookie = useCookie("hash-locale");
|
|
@@ -77,6 +84,10 @@ function switchLocale(fromLocale, toLocale, route, router, i18nConfig, i18nRoute
|
|
|
77
84
|
console.warn(`Locale ${toLocale} is not available`);
|
|
78
85
|
return Promise.reject(`Locale ${toLocale} is not available`);
|
|
79
86
|
}
|
|
87
|
+
if (isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
88
|
+
const userLocaleCookie = useCookie("no-prefix-locale");
|
|
89
|
+
userLocaleCookie.value = toLocale;
|
|
90
|
+
}
|
|
80
91
|
const switchedRoute = switchLocaleRoute(
|
|
81
92
|
fromLocale,
|
|
82
93
|
toLocale,
|
|
@@ -88,9 +99,12 @@ function switchLocale(fromLocale, toLocale, route, router, i18nConfig, i18nRoute
|
|
|
88
99
|
if (typeof switchedRoute === "string" && switchedRoute.startsWith("http")) {
|
|
89
100
|
return navigateTo(switchedRoute, { redirectCode: 200, external: true });
|
|
90
101
|
}
|
|
102
|
+
if (isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
103
|
+
return navigateTo(switchedRoute, { redirectCode: 200, external: true });
|
|
104
|
+
}
|
|
91
105
|
return router.push(switchedRoute);
|
|
92
106
|
}
|
|
93
|
-
function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
107
|
+
function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale, noPrefixStrategy) {
|
|
94
108
|
const resolveParams = (to2) => {
|
|
95
109
|
const params = typeof to2 === "object" && "params" in to2 && typeof to2.params === "object" ? { ...to2.params } : {};
|
|
96
110
|
if (typeof to2 === "string") {
|
|
@@ -101,7 +115,7 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
|
101
115
|
}
|
|
102
116
|
return params;
|
|
103
117
|
};
|
|
104
|
-
if (i18nConfig.
|
|
118
|
+
if (withPrefixStrategy(i18nConfig.strategy)) {
|
|
105
119
|
const defaultLocale = i18nConfig.defaultLocale;
|
|
106
120
|
let resolvedTo = to;
|
|
107
121
|
if (typeof to === "string") {
|
|
@@ -124,13 +138,13 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
|
124
138
|
});
|
|
125
139
|
}
|
|
126
140
|
}
|
|
127
|
-
const currentLocale = locale || getCurrentLocale(route, i18nConfig, hashLocale);
|
|
141
|
+
const currentLocale = locale || getCurrentLocale(route, i18nConfig, hashLocale, noPrefixStrategy);
|
|
128
142
|
const selectRoute = router.resolve(to);
|
|
129
143
|
const routeName = getRouteName(selectRoute, currentLocale).replace(new RegExp(`-${i18nConfig.defaultLocale}$`), "");
|
|
130
144
|
if (!routeName || routeName === "") {
|
|
131
145
|
const resolved = router.resolve(to);
|
|
132
146
|
let url = resolved.path.replace(new RegExp(`^/${currentLocale}/`), "/");
|
|
133
|
-
if (currentLocale !== i18nConfig.defaultLocale || i18nConfig.
|
|
147
|
+
if (currentLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy)) {
|
|
134
148
|
url = "/" + currentLocale + url;
|
|
135
149
|
}
|
|
136
150
|
return router.resolve({
|
|
@@ -149,7 +163,7 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
|
149
163
|
hash: selectRoute.hash
|
|
150
164
|
});
|
|
151
165
|
}
|
|
152
|
-
const newRouteName = currentLocale !== i18nConfig.defaultLocale || i18nConfig.
|
|
166
|
+
const newRouteName = currentLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy) ? `localized-${routeName}` : routeName;
|
|
153
167
|
if (!router.hasRoute(newRouteName)) {
|
|
154
168
|
const newParams2 = resolveParams(to);
|
|
155
169
|
delete newParams2.locale;
|
|
@@ -165,7 +179,7 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
|
165
179
|
}
|
|
166
180
|
const newParams = resolveParams(to);
|
|
167
181
|
delete newParams.locale;
|
|
168
|
-
if (currentLocale !== i18nConfig.defaultLocale || i18nConfig.
|
|
182
|
+
if (currentLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy)) {
|
|
169
183
|
newParams.locale = currentLocale;
|
|
170
184
|
}
|
|
171
185
|
return router.resolve({
|
|
@@ -189,6 +203,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
189
203
|
const i18nConfig = config.public.i18nConfig;
|
|
190
204
|
const apiBaseUrl = i18nConfig.apiBaseUrl ?? "_locales";
|
|
191
205
|
const runtimeConfig = useRuntimeConfig();
|
|
206
|
+
const noPrefixDefault = isNoPrefixStrategy(i18nConfig.strategy) ? useCookie("no-prefix-locale").value ?? i18nConfig.defaultLocale : null;
|
|
192
207
|
const loadTranslationsIfNeeded = async (locale, routeName, path) => {
|
|
193
208
|
try {
|
|
194
209
|
if (!i18nHelper.hasPageTranslation(locale, routeName)) {
|
|
@@ -207,9 +222,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
207
222
|
} catch (_error) {
|
|
208
223
|
}
|
|
209
224
|
};
|
|
210
|
-
async function
|
|
225
|
+
async function loadGlobalTranslations(to) {
|
|
211
226
|
const hashLocale2 = i18nConfig.hashMode ? nuxtApp.runWithContext(() => (useCookie("hash-locale").value ?? i18nConfig.defaultLocale).toString()).toString() : null;
|
|
212
|
-
const locale = getCurrentLocale(to, i18nConfig, hashLocale2);
|
|
227
|
+
const locale = getCurrentLocale(to, i18nConfig, hashLocale2, noPrefixDefault);
|
|
213
228
|
if (!i18nHelper.hasGeneralTranslation(locale)) {
|
|
214
229
|
const data = await $fetch(`/${apiBaseUrl}/general/${locale}/data.json?v=${i18nConfig.dateBuild}`, {
|
|
215
230
|
baseURL: runtimeConfig.app.baseURL
|
|
@@ -228,18 +243,18 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
228
243
|
const router = useRouter();
|
|
229
244
|
router.beforeEach(async (to, from, next) => {
|
|
230
245
|
if (to.path !== from.path) {
|
|
231
|
-
await
|
|
246
|
+
await loadGlobalTranslations(to);
|
|
232
247
|
}
|
|
233
248
|
if (next) {
|
|
234
249
|
next();
|
|
235
250
|
}
|
|
236
251
|
});
|
|
237
|
-
await
|
|
252
|
+
await loadGlobalTranslations(router.currentRoute.value);
|
|
238
253
|
const getTranslation = (key, params, defaultValue) => {
|
|
239
254
|
if (!key) return "";
|
|
240
255
|
const route = router.currentRoute.value;
|
|
241
256
|
const hashLocale2 = i18nConfig.hashMode ? (useCookie("hash-locale").value ?? i18nConfig.defaultLocale).toString() : null;
|
|
242
|
-
const locale = getCurrentLocale(route, i18nConfig, hashLocale2);
|
|
257
|
+
const locale = getCurrentLocale(route, i18nConfig, hashLocale2, noPrefixDefault);
|
|
243
258
|
const routeName = getRouteName(route, locale);
|
|
244
259
|
let value = i18nHelper.getTranslation(locale, routeName, key);
|
|
245
260
|
if (!value) {
|
|
@@ -261,12 +276,12 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
261
276
|
const provideData = {
|
|
262
277
|
i18n: void 0,
|
|
263
278
|
__micro: true,
|
|
264
|
-
getLocale: () => getCurrentLocale(router.currentRoute.value, i18nConfig, hashLocale),
|
|
265
|
-
getLocaleName: () => getCurrentName(router.currentRoute.value, i18nConfig, hashLocale),
|
|
279
|
+
getLocale: () => getCurrentLocale(router.currentRoute.value, i18nConfig, hashLocale, noPrefixDefault),
|
|
280
|
+
getLocaleName: () => getCurrentName(router.currentRoute.value, i18nConfig, hashLocale, noPrefixDefault),
|
|
266
281
|
defaultLocale: () => i18nConfig.defaultLocale,
|
|
267
282
|
getLocales: () => i18nConfig.locales || [],
|
|
268
283
|
getRouteName: (route, locale) => {
|
|
269
|
-
const selectedLocale = locale ?? getCurrentLocale(router.currentRoute.value, i18nConfig, hashLocale);
|
|
284
|
+
const selectedLocale = locale ?? getCurrentLocale(router.currentRoute.value, i18nConfig, hashLocale, noPrefixDefault);
|
|
270
285
|
const selectedRoute = route ?? router.currentRoute.value;
|
|
271
286
|
return getRouteName(selectedRoute, selectedLocale);
|
|
272
287
|
},
|
|
@@ -277,18 +292,18 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
277
292
|
},
|
|
278
293
|
tc: (key, params, defaultValue) => {
|
|
279
294
|
const route = router.currentRoute.value;
|
|
280
|
-
const currentLocale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
295
|
+
const currentLocale = getCurrentLocale(route, i18nConfig, hashLocale, noPrefixDefault);
|
|
281
296
|
const { count, ..._params } = typeof params === "number" ? { count: params } : params;
|
|
282
297
|
return plural(key, Number.parseInt(count.toString()), _params, currentLocale, getTranslation) ?? defaultValue ?? key;
|
|
283
298
|
},
|
|
284
299
|
tn: (value, options) => {
|
|
285
300
|
const route = router.currentRoute.value;
|
|
286
|
-
const locale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
301
|
+
const locale = getCurrentLocale(route, i18nConfig, hashLocale, noPrefixDefault);
|
|
287
302
|
return formatNumber(value, locale, options);
|
|
288
303
|
},
|
|
289
304
|
td: (value, options) => {
|
|
290
305
|
const route = router.currentRoute.value;
|
|
291
|
-
const locale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
306
|
+
const locale = getCurrentLocale(route, i18nConfig, hashLocale, noPrefixDefault);
|
|
292
307
|
return formatDate(value, locale, options);
|
|
293
308
|
},
|
|
294
309
|
has: (key) => {
|
|
@@ -296,13 +311,13 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
296
311
|
},
|
|
297
312
|
mergeTranslations: (newTranslations) => {
|
|
298
313
|
const route = router.currentRoute.value;
|
|
299
|
-
const locale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
314
|
+
const locale = getCurrentLocale(route, i18nConfig, hashLocale, noPrefixDefault);
|
|
300
315
|
const routeName = getRouteName(route, locale);
|
|
301
316
|
i18nHelper.mergeTranslation(locale, routeName, newTranslations);
|
|
302
317
|
},
|
|
303
318
|
switchLocaleRoute: (toLocale) => {
|
|
304
319
|
const route = router.currentRoute.value;
|
|
305
|
-
const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
320
|
+
const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale, noPrefixDefault);
|
|
306
321
|
if (i18nConfig.hashMode) {
|
|
307
322
|
hashLocale = toLocale;
|
|
308
323
|
}
|
|
@@ -310,7 +325,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
310
325
|
},
|
|
311
326
|
switchLocalePath: (toLocale) => {
|
|
312
327
|
const route = router.currentRoute.value;
|
|
313
|
-
const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
328
|
+
const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale, noPrefixDefault);
|
|
314
329
|
if (i18nConfig.hashMode) {
|
|
315
330
|
hashLocale = toLocale;
|
|
316
331
|
}
|
|
@@ -325,7 +340,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
325
340
|
},
|
|
326
341
|
switchLocale: (toLocale) => {
|
|
327
342
|
const route = router.currentRoute.value;
|
|
328
|
-
const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
343
|
+
const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale, noPrefixDefault);
|
|
329
344
|
if (i18nConfig.hashMode) {
|
|
330
345
|
hashLocale = toLocale;
|
|
331
346
|
}
|
|
@@ -335,7 +350,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
335
350
|
if (typeof route === "string") {
|
|
336
351
|
route = router.resolve(route);
|
|
337
352
|
}
|
|
338
|
-
const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
353
|
+
const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale, noPrefixDefault);
|
|
339
354
|
if (i18nConfig.hashMode) {
|
|
340
355
|
hashLocale = toLocale ?? fromLocale;
|
|
341
356
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isPrefixStrategy } from "../helpers.js";
|
|
1
2
|
import { defineNuxtPlugin, navigateTo, useNuxtApp, useRuntimeConfig } from "#app";
|
|
2
3
|
import { useRoute, useRouter } from "#imports";
|
|
3
4
|
export default defineNuxtPlugin(async (_nuxtApp) => {
|
|
@@ -35,12 +36,12 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
|
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
if (import.meta.server) {
|
|
38
|
-
if (i18nConfig.
|
|
39
|
+
if (isPrefixStrategy(i18nConfig.strategy)) {
|
|
39
40
|
await handleRedirect(route);
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
router.beforeEach(async (to, from, next) => {
|
|
43
|
-
if (i18nConfig.
|
|
44
|
+
if (isPrefixStrategy(i18nConfig.strategy)) {
|
|
44
45
|
await handleRedirect(to);
|
|
45
46
|
}
|
|
46
47
|
if (next) {
|
|
@@ -61,7 +62,7 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
|
|
|
61
62
|
const resolvedRoute = router.resolve({ name: defaultRouteName });
|
|
62
63
|
const newParams = { ...route.params };
|
|
63
64
|
delete newParams.locale;
|
|
64
|
-
if (i18nConfig.
|
|
65
|
+
if (isPrefixStrategy(i18nConfig.strategy)) {
|
|
65
66
|
if (router.hasRoute(`localized-${defaultRouteName}-${currentLocale}`)) {
|
|
66
67
|
defaultRouteName = `localized-${defaultRouteName}-${currentLocale}`;
|
|
67
68
|
} else {
|