@i18n-micro/core 1.1.0 → 1.1.1
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/index.cjs +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +129 -315
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/dist/route-service.d.ts +0 -41
- package/src/route-service.ts +0 -469
- package/tests/route-service.test.ts +0 -347
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(o,e){if(!o||typeof e!="string")return null;if(e in o){const s=o[e];return s}const t=e.split(".");let r=o;for(const s of t)if(r&&typeof r=="object"&&s in r)r=r[s];else return null;return r??null}function y(o){const e=o?.translations??new Map;return{hasCache(t,r){const s=`${t}:${r}`;return e.has(s)||e.has(t)},getCache(t,r){const s=`${t}:${r}`;return e.get(s)},setCache(t,r,s){},hasTranslation(t,r){for(const[s,i]of e)if((s===t||s.startsWith(`${t}:`))&&d(i,r)!==null)return!0;return!1},hasGeneralTranslation(t){return e.has(t)},hasPageTranslation(t,r){return e.has(`${t}:${r}`)},getTranslation(t,r,s){const i=`${t}:${r}`,n=e.get(i),a=d(n,s);if(a!==null)return a;const l=e.get(t);return d(l,s)},loadTranslations(t,r){const s=e.get(t)??{};e.set(t,{...s,...r})},setTranslations(t,r){e.set(t,r)},loadPageTranslations(t,r,s){const i=`${t}:${r}`,n=e.get(i);!n||Object.keys(n).length===0?e.set(i,s):e.set(i,{...n,...s})},mergeTranslation(t,r,s,i=!1){const n=`${t}:${r}`,a=e.get(n)??{};e.set(n,{...a,...s})},mergeGlobalTranslation(t,r,s=!1){const i=e.get(t)??{};e.set(t,{...i,...r})},clearCache(){e.clear()}}}const L=/\{(\w+)\}/g;function C(o,e){return e?o.replace(L,(t,r)=>{const s=e[r];return s!==void 0?String(s):`{${r}}`}):o}function f(o){return o==="prefix"||o==="prefix_and_default"}function h(o){return o==="no_prefix"}function b(o){return o==="prefix"}function P(o){return o==="prefix_except_default"}function R(o){return o==="prefix_and_default"}const $=(o,e,t,r,s)=>{const i=s(o,t);if(!i)return null;const n=i.toString().split("|");if(n.length===0)return null;const a=e<n.length?n[e]:n[n.length-1];return a?a.trim().replace("{count}",e.toString()):null};class w{constructor(e,t,r,s,i,n){this.i18nConfig=e,this.router=t,this.hashLocaleDefault=r,this.noPrefixDefault=s,this.navigateTo=i,this.getDefaultLocale=n}extractLocaleFromPath(e){if(!e)return null;const r=e.split("?")[0]?.split("#")[0];if(!r||r==="/")return null;const s=r.split("/").filter(Boolean);if(s.length===0)return null;const i=s[0];return i&&(this.i18nConfig.locales?.map(a=>a.code)||[]).includes(i)?i:null}getCurrentLocale(e){if(e=e??this.router.currentRoute.value,this.i18nConfig.hashMode){const i=this.getDefaultLocale?.();if(i)return i;if(this.hashLocaleDefault)return this.hashLocaleDefault}if(h(this.i18nConfig.strategy)){const i=this.getDefaultLocale?.();if(i)return i;if(this.noPrefixDefault)return this.noPrefixDefault}const t=e.path||e.fullPath||"";if(R(this.i18nConfig.strategy)&&(t==="/"||t==="")){const i=this.getDefaultLocale?.();if(i)return i}if(e.params?.locale)return e.params.locale.toString();const r=this.extractLocaleFromPath(t);if(r)return r;if(P(this.i18nConfig.strategy))return(this.i18nConfig.defaultLocale||"en").toString();const s=this.getDefaultLocale?.();return s||(this.i18nConfig.defaultLocale||"en").toString()}getCurrentName(e){const t=this.getCurrentLocale(e);return this.i18nConfig.locales?.find(s=>s.code===t)?.displayName??null}getRouteName(e,t){return(e.name??"").toString().toString().replace("localized-","").replace(new RegExp(`-${t}$`),"")}getPluginRouteName(e,t){return this.i18nConfig.disablePageLocales?"general":this.getRouteName(e,t)}getFullPathWithBaseUrl(e,t){let s=this.router.resolve(t).fullPath;e?.baseDefault&&(s=s.replace(new RegExp(`^/${e.code}`),""));let i=e.baseUrl;return i||(i=""),i?.endsWith("/")&&(i=i.slice(0,-1)),i+s}switchLocaleRoute(e,t,r,s){const i=this.i18nConfig.locales?.find(g=>g.code===t),n=this.getRouteName(r,e);if(this.router.hasRoute(`localized-${n}-${t}`)){const m={...s?.[t]?{...s[t]}:{...r.params??{}}};delete m.locale,h(this.i18nConfig.strategy)||(m.locale=t);const v={name:`localized-${n}-${t}`,params:m,query:r.query,hash:r.hash};return i?.baseUrl?this.getFullPathWithBaseUrl(i,v):v}let a=n;const u={...s?.[t]?{...s[t]}:{...r.params??{}}};delete u.locale,h(this.i18nConfig.strategy)||(n==="custom-fallback-route"?a=n:a=t!==this.i18nConfig.defaultLocale||f(this.i18nConfig.strategy)?`localized-${n}`:n,h(this.i18nConfig.strategy)||(t!==this.i18nConfig.defaultLocale||f(this.i18nConfig.strategy))&&(u.locale=t));const c={name:a,params:u,query:r.query,hash:r.hash};return h(this.i18nConfig.strategy)&&this.i18nConfig.locales?.forEach((g,m)=>{c.name.endsWith(`-${g.code}`)&&(c.name=c.name.slice(0,-g.code-1))}),i?.baseUrl?this.getFullPathWithBaseUrl(i,c):c}resolveParams(e){const t=typeof e=="object"&&"params"in e&&typeof e.params=="object"?{...e.params}:{};if(typeof e=="string"){const r=this.router.resolve(e);r&&r.params&&Object.assign(t,r.params)}return t}handlePrefixStrategy(e){if(!f(this.i18nConfig.strategy))return e;const t=this.i18nConfig.defaultLocale;let r=e;typeof e=="string"&&(r=this.router.resolve("/"+t+e));const s=this.getRouteName(r,t),i=this.resolveParams(r);return h(this.i18nConfig.strategy)||(i.locale=t),this.router.hasRoute(`localized-${s}`)?this.router.resolve({name:`localized-${s}`,query:r.query,hash:r.hash,params:i}):this.router.hasRoute(`localized-${s}-${t}`)?this.router.resolve({name:`localized-${s}-${t}`,query:r.query,hash:r.hash,params:i}):e}createLocalizedRoute(e,t,r){const s=this.router.resolve(e),i=this.getRouteName(s,r).replace(new RegExp(`-${this.i18nConfig.defaultLocale}$`),"");if(!h(this.i18nConfig.strategy)&&(!i||i==="")){let u=this.router.resolve(e).path.replace(new RegExp(`^/${r}/`),"/");return(r!==this.i18nConfig.defaultLocale||f(this.i18nConfig.strategy))&&(u="/"+r+u),this.router.resolve({path:u,query:s.query,hash:s.hash})}if(this.router.hasRoute(`localized-${i}-${r}`)){const l=this.resolveParams(s);return h(this.i18nConfig.strategy)||(l.locale=r),this.router.resolve({name:`localized-${i}-${r}`,params:l,query:s.query,hash:s.hash})}const n=r!==this.i18nConfig.defaultLocale||f(this.i18nConfig.strategy)?`localized-${i}`:i;if(!this.router.hasRoute(n)){const l=this.resolveParams(e);return delete l.locale,this.router.hasRoute(i)?this.router.resolve({name:i,params:l,query:s.query,hash:s.hash}):this.router.resolve("/")}const a=this.resolveParams(e);return delete a.locale,h(this.i18nConfig.strategy)||(r!==this.i18nConfig.defaultLocale||f(this.i18nConfig.strategy))&&(a.locale=r),this.router.resolve({name:n,params:a,query:s.query,hash:s.hash})}getLocalizedRoute(e,t,r){const s=r||this.getCurrentLocale(t),i=this.handlePrefixStrategy(e);return this.createLocalizedRoute(i,t,s)}getCurrentRoute(){return this.router.currentRoute.value}resolveRouteWithStrategy(e,t,r){return h(this.i18nConfig.strategy)?this.router.resolve(e):t!==this.i18nConfig.defaultLocale||f(this.i18nConfig.strategy)?this.router.resolve(`/${r}${e}`):this.router.resolve(e)}switchLocaleLogic(e,t,r){const s=this.getCurrentLocale();let i;typeof r=="string"?i=this.resolveRouteWithStrategy(r,e,s):i=r??this.getCurrentRoute();const n=this.switchLocaleRoute(s,e,i,t);return typeof n=="string"&&n.startsWith("http")?this.navigateTo(n,{redirectCode:200,external:!0}):(h(this.i18nConfig.strategy)&&(n.force=!0),this.router.push(n))}resolveLocalizedRoute(e,t){const r=this.getCurrentRoute(),s=this.getCurrentLocale(),i=t??s;let n;if(typeof e=="string")if(e.startsWith("/"))n=this.resolveRouteWithStrategy(e,i,s);else{const a=e;this.router.hasRoute(a)?n=this.router.resolve({name:a}):(e=`/${e}`,n=this.resolveRouteWithStrategy(e,i,s))}else n=e;return this.getLocalizedRoute(n,r,i)}}class p{formatNumber(e,t,r){return new Intl.NumberFormat(t,r).format(e)}formatDate(e,t,r){const s=new Date(e);return Number.isNaN(s.getTime())?"Invalid Date":new Intl.DateTimeFormat(t,r).format(s)}formatRelativeTime(e,t,r){const s=new Date(e);if(Number.isNaN(s.getTime()))return new Intl.RelativeTimeFormat(t,r).format(0,"second");const n=Math.floor((new Date().getTime()-s.getTime())/1e3),a=[{unit:"year",seconds:31536e3},{unit:"month",seconds:2592e3},{unit:"day",seconds:86400},{unit:"hour",seconds:3600},{unit:"minute",seconds:60},{unit:"second",seconds:1}];for(const{unit:l,seconds:u}of a){const c=Math.floor(n/u);if(c>=1)return new Intl.RelativeTimeFormat(t,r).format(-c,l)}return new Intl.RelativeTimeFormat(t,r).format(0,"second")}}class S{constructor(e={}){this.formatter=new p,this.helper=y(e.storage),this.formatter=new p,this.pluralFunc=e.plural||$,this.missingWarn=e.missingWarn??!0,this.missingHandler=e.missingHandler,this.getPreviousPageInfo=e.getPreviousPageInfo,this.getCustomMissingHandler=e.getCustomMissingHandler,this.enablePreviousPageFallback=e.enablePreviousPageFallback??!1}t(e,t,r,s){if(!e)return"";const i=this.getLocale(),n=s||this.getRoute();let a=this.helper.getTranslation(i,n,e);if(!a&&this.enablePreviousPageFallback&&this.getPreviousPageInfo){const l=this.getPreviousPageInfo();if(l){const u=this.helper.getTranslation(l.locale,l.routeName,e);u&&(a=u,process.env.NODE_ENV!=="production"&&console.log(`Using fallback translation from previous route: ${l.routeName} -> ${e}`))}}if(!a){const l=this.getFallbackLocale();i!==l&&(a=this.helper.getTranslation(l,n,e))}if(!a){const l=this.getCustomMissingHandler?.();l?l(i,e,n):this.missingHandler?this.missingHandler(i,e,n):this.missingWarn&&process.env.NODE_ENV!=="production"&&typeof window<"u"&&console.warn(`Not found '${e}' key in '${i}' locale messages for route '${n}'.`),a=r===void 0?e:r||e}return typeof a=="string"&&t?C(a,t):a}ts(e,t,r,s){return this.t(e,t,r,s)?.toString()??r??e}tc(e,t,r){const{count:s,...i}=typeof t=="number"?{count:t}:t;if(s===void 0)return r??e;const n=(l,u,c)=>this.t(l,u,c);return this.pluralFunc(e,Number.parseInt(s.toString()),i,this.getLocale(),n)??r??e}tn(e,t){return this.formatter.formatNumber(e,this.getLocale(),t)}td(e,t){return this.formatter.formatDate(e,this.getLocale(),t)}tdr(e,t){return this.formatter.formatRelativeTime(e,this.getLocale(),t)}has(e,t){const r=t||this.getRoute(),s=this.getLocale();return!!this.helper.getTranslation(s,r,e)}clearCache(){this.helper.clearCache()}loadTranslationsCore(e,t,r){r?this.helper.mergeGlobalTranslation(e,t,!0):this.helper.setTranslations(e,t)}loadRouteTranslationsCore(e,t,r,s){s?this.helper.mergeTranslation(e,t,r,!0):this.helper.loadPageTranslations(e,t,r)}}exports.BaseI18n=S;exports.FormatService=p;exports.RouteService=w;exports.defaultPlural=$;exports.interpolate=C;exports.isNoPrefixStrategy=h;exports.isPrefixAndDefaultStrategy=R;exports.isPrefixExceptDefaultStrategy=P;exports.isPrefixStrategy=b;exports.useTranslationHelper=y;exports.withPrefixStrategy=f;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function f(s,e){if(!s||typeof e!="string")return null;if(e in s){const n=s[e];return n}const t=e.split(".");let r=s;for(const n of t)if(r&&typeof r=="object"&&n in r)r=r[n];else return null;return r??null}function h(s){const e=s?.translations??new Map;return{hasCache(t,r){const n=`${t}:${r}`;return e.has(n)||e.has(t)},getCache(t,r){const n=`${t}:${r}`;return e.get(n)},setCache(t,r,n){},hasTranslation(t,r){for(const[n,a]of e)if((n===t||n.startsWith(`${t}:`))&&f(a,r)!==null)return!0;return!1},hasGeneralTranslation(t){return e.has(t)},hasPageTranslation(t,r){return e.has(`${t}:${r}`)},getTranslation(t,r,n){const a=`${t}:${r}`,i=e.get(a),o=f(i,n);if(o!==null)return o;const l=e.get(t);return f(l,n)},loadTranslations(t,r){const n=e.get(t)??{};e.set(t,{...n,...r})},setTranslations(t,r){e.set(t,r)},loadPageTranslations(t,r,n){const a=`${t}:${r}`,i=e.get(a);!i||Object.keys(i).length===0?e.set(a,n):e.set(a,{...i,...n})},mergeTranslation(t,r,n,a=!1){const i=`${t}:${r}`,o=e.get(i)??{};e.set(i,{...o,...n})},mergeGlobalTranslation(t,r,n=!1){const a=e.get(t)??{};e.set(t,{...a,...r})},clearCache(){e.clear()}}}class g{formatNumber(e,t,r){return new Intl.NumberFormat(t,r).format(e)}formatDate(e,t,r){const n=new Date(e);return Number.isNaN(n.getTime())?"Invalid Date":new Intl.DateTimeFormat(t,r).format(n)}formatRelativeTime(e,t,r){const n=new Date(e);if(Number.isNaN(n.getTime()))return new Intl.RelativeTimeFormat(t,r).format(0,"second");const i=Math.floor((new Date().getTime()-n.getTime())/1e3),o=[{unit:"year",seconds:31536e3},{unit:"month",seconds:2592e3},{unit:"day",seconds:86400},{unit:"hour",seconds:3600},{unit:"minute",seconds:60},{unit:"second",seconds:1}];for(const{unit:l,seconds:u}of o){const c=Math.floor(i/u);if(c>=1)return new Intl.RelativeTimeFormat(t,r).format(-c,l)}return new Intl.RelativeTimeFormat(t,r).format(0,"second")}}const p=/\{(\w+)\}/g;function m(s,e){return e?s.replace(p,(t,r)=>{const n=e[r];return n!==void 0?String(n):`{${r}}`}):s}function v(s){return s==="prefix"||s==="prefix_and_default"}function T(s){return s==="no_prefix"}function P(s){return s==="prefix"}function b(s){return s==="prefix_except_default"}function x(s){return s==="prefix_and_default"}const d=(s,e,t,r,n)=>{const a=n(s,t);if(!a)return null;const i=a.toString().split("|");if(i.length===0)return null;const o=e<i.length?i[e]:i[i.length-1];return o?o.trim().replace("{count}",e.toString()):null};class N{constructor(e={}){this.formatter=new g,this.helper=h(e.storage),this.formatter=new g,this.pluralFunc=e.plural||d,this.missingWarn=e.missingWarn??!0,this.missingHandler=e.missingHandler,this.getPreviousPageInfo=e.getPreviousPageInfo,this.getCustomMissingHandler=e.getCustomMissingHandler,this.enablePreviousPageFallback=e.enablePreviousPageFallback??!1}t(e,t,r,n){if(!e)return"";const a=this.getLocale(),i=n||this.getRoute();let o=this.helper.getTranslation(a,i,e);if(!o&&this.enablePreviousPageFallback&&this.getPreviousPageInfo){const l=this.getPreviousPageInfo();if(l){const u=this.helper.getTranslation(l.locale,l.routeName,e);u&&(o=u,process.env.NODE_ENV!=="production"&&console.log(`Using fallback translation from previous route: ${l.routeName} -> ${e}`))}}if(!o){const l=this.getFallbackLocale();a!==l&&(o=this.helper.getTranslation(l,i,e))}if(!o){const l=this.getCustomMissingHandler?.();l?l(a,e,i):this.missingHandler?this.missingHandler(a,e,i):this.missingWarn&&process.env.NODE_ENV!=="production"&&typeof window<"u"&&console.warn(`Not found '${e}' key in '${a}' locale messages for route '${i}'.`),o=r===void 0?e:r||e}return typeof o=="string"&&t?m(o,t):o}ts(e,t,r,n){return this.t(e,t,r,n)?.toString()??r??e}tc(e,t,r){const{count:n,...a}=typeof t=="number"?{count:t}:t;if(n===void 0)return r??e;const i=(l,u,c)=>this.t(l,u,c);return this.pluralFunc(e,Number.parseInt(n.toString()),a,this.getLocale(),i)??r??e}tn(e,t){return this.formatter.formatNumber(e,this.getLocale(),t)}td(e,t){return this.formatter.formatDate(e,this.getLocale(),t)}tdr(e,t){return this.formatter.formatRelativeTime(e,this.getLocale(),t)}has(e,t){const r=t||this.getRoute(),n=this.getLocale();return!!this.helper.getTranslation(n,r,e)}clearCache(){this.helper.clearCache()}loadTranslationsCore(e,t,r){r?this.helper.mergeGlobalTranslation(e,t,!0):this.helper.setTranslations(e,t)}loadRouteTranslationsCore(e,t,r,n){n?this.helper.mergeTranslation(e,t,r,!0):this.helper.loadPageTranslations(e,t,r)}}exports.BaseI18n=N;exports.FormatService=g;exports.defaultPlural=d;exports.interpolate=m;exports.isNoPrefixStrategy=T;exports.isPrefixAndDefaultStrategy=x;exports.isPrefixExceptDefaultStrategy=b;exports.isPrefixStrategy=P;exports.useTranslationHelper=h;exports.withPrefixStrategy=v;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useTranslationHelper, TranslationStorage } from './translation';
|
|
2
|
-
import { RouteService } from './route-service';
|
|
3
2
|
import { FormatService } from './format-service';
|
|
4
3
|
import { interpolate, withPrefixStrategy, isNoPrefixStrategy, isPrefixStrategy, isPrefixExceptDefaultStrategy, isPrefixAndDefaultStrategy, defaultPlural } from './helpers';
|
|
5
4
|
import { BaseI18n, BaseI18nOptions } from './base';
|
|
6
|
-
export { useTranslationHelper, interpolate, withPrefixStrategy, isNoPrefixStrategy, isPrefixStrategy, isPrefixExceptDefaultStrategy, isPrefixAndDefaultStrategy, defaultPlural,
|
|
5
|
+
export { useTranslationHelper, interpolate, withPrefixStrategy, isNoPrefixStrategy, isPrefixStrategy, isPrefixExceptDefaultStrategy, isPrefixAndDefaultStrategy, defaultPlural, FormatService, BaseI18n, type TranslationStorage, type BaseI18nOptions, };
|
package/dist/index.mjs
CHANGED
|
@@ -1,302 +1,86 @@
|
|
|
1
|
-
function
|
|
2
|
-
if (!
|
|
3
|
-
if (e in
|
|
4
|
-
const
|
|
5
|
-
return
|
|
1
|
+
function f(s, e) {
|
|
2
|
+
if (!s || typeof e != "string") return null;
|
|
3
|
+
if (e in s) {
|
|
4
|
+
const r = s[e];
|
|
5
|
+
return r;
|
|
6
6
|
}
|
|
7
7
|
const t = e.split(".");
|
|
8
|
-
let
|
|
9
|
-
for (const
|
|
10
|
-
if (
|
|
11
|
-
|
|
8
|
+
let n = s;
|
|
9
|
+
for (const r of t)
|
|
10
|
+
if (n && typeof n == "object" && r in n)
|
|
11
|
+
n = n[r];
|
|
12
12
|
else
|
|
13
13
|
return null;
|
|
14
|
-
return
|
|
14
|
+
return n ?? null;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
const e =
|
|
16
|
+
function h(s) {
|
|
17
|
+
const e = s?.translations ?? /* @__PURE__ */ new Map();
|
|
18
18
|
return {
|
|
19
|
-
hasCache(t,
|
|
20
|
-
const
|
|
21
|
-
return e.has(
|
|
19
|
+
hasCache(t, n) {
|
|
20
|
+
const r = `${t}:${n}`;
|
|
21
|
+
return e.has(r) || e.has(t);
|
|
22
22
|
},
|
|
23
|
-
getCache(t,
|
|
24
|
-
const
|
|
25
|
-
return e.get(
|
|
23
|
+
getCache(t, n) {
|
|
24
|
+
const r = `${t}:${n}`;
|
|
25
|
+
return e.get(r);
|
|
26
26
|
},
|
|
27
|
-
setCache(t,
|
|
27
|
+
setCache(t, n, r) {
|
|
28
28
|
},
|
|
29
|
-
hasTranslation(t,
|
|
30
|
-
for (const [
|
|
31
|
-
if ((
|
|
29
|
+
hasTranslation(t, n) {
|
|
30
|
+
for (const [r, a] of e)
|
|
31
|
+
if ((r === t || r.startsWith(`${t}:`)) && f(a, n) !== null)
|
|
32
32
|
return !0;
|
|
33
33
|
return !1;
|
|
34
34
|
},
|
|
35
35
|
hasGeneralTranslation(t) {
|
|
36
36
|
return e.has(t);
|
|
37
37
|
},
|
|
38
|
-
hasPageTranslation(t,
|
|
39
|
-
return e.has(`${t}:${
|
|
38
|
+
hasPageTranslation(t, n) {
|
|
39
|
+
return e.has(`${t}:${n}`);
|
|
40
40
|
},
|
|
41
|
-
getTranslation(t,
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
41
|
+
getTranslation(t, n, r) {
|
|
42
|
+
const a = `${t}:${n}`, i = e.get(a), o = f(i, r);
|
|
43
|
+
if (o !== null) return o;
|
|
44
44
|
const l = e.get(t);
|
|
45
|
-
return
|
|
45
|
+
return f(l, r);
|
|
46
46
|
},
|
|
47
|
-
loadTranslations(t,
|
|
48
|
-
const
|
|
49
|
-
e.set(t, { ...
|
|
47
|
+
loadTranslations(t, n) {
|
|
48
|
+
const r = e.get(t) ?? {};
|
|
49
|
+
e.set(t, { ...r, ...n });
|
|
50
50
|
},
|
|
51
|
-
setTranslations(t,
|
|
52
|
-
e.set(t,
|
|
51
|
+
setTranslations(t, n) {
|
|
52
|
+
e.set(t, n);
|
|
53
53
|
},
|
|
54
|
-
loadPageTranslations(t,
|
|
55
|
-
const
|
|
56
|
-
!i || Object.keys(i).length === 0 ? e.set(
|
|
54
|
+
loadPageTranslations(t, n, r) {
|
|
55
|
+
const a = `${t}:${n}`, i = e.get(a);
|
|
56
|
+
!i || Object.keys(i).length === 0 ? e.set(a, r) : e.set(a, { ...i, ...r });
|
|
57
57
|
},
|
|
58
|
-
mergeTranslation(t,
|
|
59
|
-
const i = `${t}:${
|
|
60
|
-
e.set(i, { ...
|
|
58
|
+
mergeTranslation(t, n, r, a = !1) {
|
|
59
|
+
const i = `${t}:${n}`, o = e.get(i) ?? {};
|
|
60
|
+
e.set(i, { ...o, ...r });
|
|
61
61
|
},
|
|
62
|
-
mergeGlobalTranslation(t,
|
|
63
|
-
const
|
|
64
|
-
e.set(t, { ...
|
|
62
|
+
mergeGlobalTranslation(t, n, r = !1) {
|
|
63
|
+
const a = e.get(t) ?? {};
|
|
64
|
+
e.set(t, { ...a, ...n });
|
|
65
65
|
},
|
|
66
66
|
clearCache() {
|
|
67
67
|
e.clear();
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
function b(o) {
|
|
85
|
-
return o === "prefix";
|
|
86
|
-
}
|
|
87
|
-
function R(o) {
|
|
88
|
-
return o === "prefix_except_default";
|
|
89
|
-
}
|
|
90
|
-
function $(o) {
|
|
91
|
-
return o === "prefix_and_default";
|
|
92
|
-
}
|
|
93
|
-
const L = (o, e, t, r, s) => {
|
|
94
|
-
const n = s(o, t);
|
|
95
|
-
if (!n)
|
|
96
|
-
return null;
|
|
97
|
-
const i = n.toString().split("|");
|
|
98
|
-
if (i.length === 0) return null;
|
|
99
|
-
const a = e < i.length ? i[e] : i[i.length - 1];
|
|
100
|
-
return a ? a.trim().replace("{count}", e.toString()) : null;
|
|
101
|
-
};
|
|
102
|
-
class w {
|
|
103
|
-
constructor(e, t, r, s, n, i) {
|
|
104
|
-
this.i18nConfig = e, this.router = t, this.hashLocaleDefault = r, this.noPrefixDefault = s, this.navigateTo = n, this.getDefaultLocale = i;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Extracts locale from URL path by checking the first path segment
|
|
108
|
-
* @param path - URL path (e.g., '/ru/sdfsdf' or '/en/about')
|
|
109
|
-
* @returns Locale code or null if not found
|
|
110
|
-
*/
|
|
111
|
-
extractLocaleFromPath(e) {
|
|
112
|
-
if (!e)
|
|
113
|
-
return null;
|
|
114
|
-
const r = e.split("?")[0]?.split("#")[0];
|
|
115
|
-
if (!r || r === "/")
|
|
116
|
-
return null;
|
|
117
|
-
const s = r.split("/").filter(Boolean);
|
|
118
|
-
if (s.length === 0)
|
|
119
|
-
return null;
|
|
120
|
-
const n = s[0];
|
|
121
|
-
return n && (this.i18nConfig.locales?.map((a) => a.code) || []).includes(n) ? n : null;
|
|
122
|
-
}
|
|
123
|
-
getCurrentLocale(e) {
|
|
124
|
-
if (e = e ?? this.router.currentRoute.value, this.i18nConfig.hashMode) {
|
|
125
|
-
const n = this.getDefaultLocale?.();
|
|
126
|
-
if (n) return n;
|
|
127
|
-
if (this.hashLocaleDefault) return this.hashLocaleDefault;
|
|
128
|
-
}
|
|
129
|
-
if (c(this.i18nConfig.strategy)) {
|
|
130
|
-
const n = this.getDefaultLocale?.();
|
|
131
|
-
if (n) return n;
|
|
132
|
-
if (this.noPrefixDefault) return this.noPrefixDefault;
|
|
133
|
-
}
|
|
134
|
-
const t = e.path || e.fullPath || "";
|
|
135
|
-
if ($(this.i18nConfig.strategy) && (t === "/" || t === "")) {
|
|
136
|
-
const n = this.getDefaultLocale?.();
|
|
137
|
-
if (n) return n;
|
|
138
|
-
}
|
|
139
|
-
if (e.params?.locale)
|
|
140
|
-
return e.params.locale.toString();
|
|
141
|
-
const r = this.extractLocaleFromPath(t);
|
|
142
|
-
if (r)
|
|
143
|
-
return r;
|
|
144
|
-
if (R(this.i18nConfig.strategy))
|
|
145
|
-
return (this.i18nConfig.defaultLocale || "en").toString();
|
|
146
|
-
const s = this.getDefaultLocale?.();
|
|
147
|
-
return s || (this.i18nConfig.defaultLocale || "en").toString();
|
|
148
|
-
}
|
|
149
|
-
getCurrentName(e) {
|
|
150
|
-
const t = this.getCurrentLocale(e);
|
|
151
|
-
return this.i18nConfig.locales?.find((s) => s.code === t)?.displayName ?? null;
|
|
152
|
-
}
|
|
153
|
-
getRouteName(e, t) {
|
|
154
|
-
return (e.name ?? "").toString().toString().replace("localized-", "").replace(new RegExp(`-${t}$`), "");
|
|
155
|
-
}
|
|
156
|
-
getPluginRouteName(e, t) {
|
|
157
|
-
return this.i18nConfig.disablePageLocales ? "general" : this.getRouteName(e, t);
|
|
158
|
-
}
|
|
159
|
-
getFullPathWithBaseUrl(e, t) {
|
|
160
|
-
let s = this.router.resolve(t).fullPath;
|
|
161
|
-
e?.baseDefault && (s = s.replace(new RegExp(`^/${e.code}`), ""));
|
|
162
|
-
let n = e.baseUrl;
|
|
163
|
-
return n || (n = ""), n?.endsWith("/") && (n = n.slice(0, -1)), n + s;
|
|
164
|
-
}
|
|
165
|
-
switchLocaleRoute(e, t, r, s) {
|
|
166
|
-
const n = this.i18nConfig.locales?.find((g) => g.code === t), i = this.getRouteName(r, e);
|
|
167
|
-
if (this.router.hasRoute(`localized-${i}-${t}`)) {
|
|
168
|
-
const m = { ...s?.[t] ? { ...s[t] } : { ...r.params ?? {} } };
|
|
169
|
-
delete m.locale, c(this.i18nConfig.strategy) || (m.locale = t);
|
|
170
|
-
const p = {
|
|
171
|
-
name: `localized-${i}-${t}`,
|
|
172
|
-
params: m,
|
|
173
|
-
query: r.query,
|
|
174
|
-
hash: r.hash
|
|
175
|
-
};
|
|
176
|
-
return n?.baseUrl ? this.getFullPathWithBaseUrl(n, p) : p;
|
|
177
|
-
}
|
|
178
|
-
let a = i;
|
|
179
|
-
const u = { ...s?.[t] ? { ...s[t] } : { ...r.params ?? {} } };
|
|
180
|
-
delete u.locale, c(this.i18nConfig.strategy) || (i === "custom-fallback-route" ? a = i : a = t !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy) ? `localized-${i}` : i, c(this.i18nConfig.strategy) || (t !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy)) && (u.locale = t));
|
|
181
|
-
const h = {
|
|
182
|
-
name: a,
|
|
183
|
-
params: u,
|
|
184
|
-
query: r.query,
|
|
185
|
-
hash: r.hash
|
|
186
|
-
};
|
|
187
|
-
return c(this.i18nConfig.strategy) && this.i18nConfig.locales?.forEach((g, m) => {
|
|
188
|
-
h.name.endsWith(`-${g.code}`) && (h.name = h.name.slice(0, -g.code - 1));
|
|
189
|
-
}), n?.baseUrl ? this.getFullPathWithBaseUrl(n, h) : h;
|
|
190
|
-
}
|
|
191
|
-
resolveParams(e) {
|
|
192
|
-
const t = typeof e == "object" && "params" in e && typeof e.params == "object" ? { ...e.params } : {};
|
|
193
|
-
if (typeof e == "string") {
|
|
194
|
-
const r = this.router.resolve(e);
|
|
195
|
-
r && r.params && Object.assign(t, r.params);
|
|
196
|
-
}
|
|
197
|
-
return t;
|
|
198
|
-
}
|
|
199
|
-
handlePrefixStrategy(e) {
|
|
200
|
-
if (!f(this.i18nConfig.strategy))
|
|
201
|
-
return e;
|
|
202
|
-
const t = this.i18nConfig.defaultLocale;
|
|
203
|
-
let r = e;
|
|
204
|
-
typeof e == "string" && (r = this.router.resolve("/" + t + e));
|
|
205
|
-
const s = this.getRouteName(r, t), n = this.resolveParams(r);
|
|
206
|
-
return c(this.i18nConfig.strategy) || (n.locale = t), this.router.hasRoute(`localized-${s}`) ? this.router.resolve({
|
|
207
|
-
name: `localized-${s}`,
|
|
208
|
-
query: r.query,
|
|
209
|
-
hash: r.hash,
|
|
210
|
-
params: n
|
|
211
|
-
}) : this.router.hasRoute(`localized-${s}-${t}`) ? this.router.resolve({
|
|
212
|
-
name: `localized-${s}-${t}`,
|
|
213
|
-
query: r.query,
|
|
214
|
-
hash: r.hash,
|
|
215
|
-
params: n
|
|
216
|
-
}) : e;
|
|
217
|
-
}
|
|
218
|
-
createLocalizedRoute(e, t, r) {
|
|
219
|
-
const s = this.router.resolve(e), n = this.getRouteName(s, r).replace(new RegExp(`-${this.i18nConfig.defaultLocale}$`), "");
|
|
220
|
-
if (!c(this.i18nConfig.strategy) && (!n || n === "")) {
|
|
221
|
-
let u = this.router.resolve(e).path.replace(new RegExp(`^/${r}/`), "/");
|
|
222
|
-
return (r !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy)) && (u = "/" + r + u), this.router.resolve({
|
|
223
|
-
path: u,
|
|
224
|
-
query: s.query,
|
|
225
|
-
hash: s.hash
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
if (this.router.hasRoute(`localized-${n}-${r}`)) {
|
|
229
|
-
const l = this.resolveParams(s);
|
|
230
|
-
return c(this.i18nConfig.strategy) || (l.locale = r), this.router.resolve({
|
|
231
|
-
name: `localized-${n}-${r}`,
|
|
232
|
-
params: l,
|
|
233
|
-
query: s.query,
|
|
234
|
-
hash: s.hash
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
const i = r !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy) ? `localized-${n}` : n;
|
|
238
|
-
if (!this.router.hasRoute(i)) {
|
|
239
|
-
const l = this.resolveParams(e);
|
|
240
|
-
return delete l.locale, this.router.hasRoute(n) ? this.router.resolve({
|
|
241
|
-
name: n,
|
|
242
|
-
params: l,
|
|
243
|
-
query: s.query,
|
|
244
|
-
hash: s.hash
|
|
245
|
-
}) : this.router.resolve("/");
|
|
246
|
-
}
|
|
247
|
-
const a = this.resolveParams(e);
|
|
248
|
-
return delete a.locale, c(this.i18nConfig.strategy) || (r !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy)) && (a.locale = r), this.router.resolve({
|
|
249
|
-
name: i,
|
|
250
|
-
params: a,
|
|
251
|
-
query: s.query,
|
|
252
|
-
hash: s.hash
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
getLocalizedRoute(e, t, r) {
|
|
256
|
-
const s = r || this.getCurrentLocale(t), n = this.handlePrefixStrategy(e);
|
|
257
|
-
return this.createLocalizedRoute(n, t, s);
|
|
258
|
-
}
|
|
259
|
-
getCurrentRoute() {
|
|
260
|
-
return this.router.currentRoute.value;
|
|
261
|
-
}
|
|
262
|
-
resolveRouteWithStrategy(e, t, r) {
|
|
263
|
-
return c(this.i18nConfig.strategy) ? this.router.resolve(e) : t !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy) ? this.router.resolve(`/${r}${e}`) : this.router.resolve(e);
|
|
264
|
-
}
|
|
265
|
-
switchLocaleLogic(e, t, r) {
|
|
266
|
-
const s = this.getCurrentLocale();
|
|
267
|
-
let n;
|
|
268
|
-
typeof r == "string" ? n = this.resolveRouteWithStrategy(r, e, s) : n = r ?? this.getCurrentRoute();
|
|
269
|
-
const i = this.switchLocaleRoute(s, e, n, t);
|
|
270
|
-
return typeof i == "string" && i.startsWith("http") ? this.navigateTo(i, { redirectCode: 200, external: !0 }) : (c(this.i18nConfig.strategy) && (i.force = !0), this.router.push(i));
|
|
271
|
-
}
|
|
272
|
-
resolveLocalizedRoute(e, t) {
|
|
273
|
-
const r = this.getCurrentRoute(), s = this.getCurrentLocale(), n = t ?? s;
|
|
274
|
-
let i;
|
|
275
|
-
if (typeof e == "string")
|
|
276
|
-
if (e.startsWith("/"))
|
|
277
|
-
i = this.resolveRouteWithStrategy(e, n, s);
|
|
278
|
-
else {
|
|
279
|
-
const a = e;
|
|
280
|
-
this.router.hasRoute(a) ? i = this.router.resolve({ name: a }) : (e = `/${e}`, i = this.resolveRouteWithStrategy(e, n, s));
|
|
281
|
-
}
|
|
282
|
-
else
|
|
283
|
-
i = e;
|
|
284
|
-
return this.getLocalizedRoute(i, r, n);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
class v {
|
|
288
|
-
formatNumber(e, t, r) {
|
|
289
|
-
return new Intl.NumberFormat(t, r).format(e);
|
|
290
|
-
}
|
|
291
|
-
formatDate(e, t, r) {
|
|
292
|
-
const s = new Date(e);
|
|
293
|
-
return Number.isNaN(s.getTime()) ? "Invalid Date" : new Intl.DateTimeFormat(t, r).format(s);
|
|
294
|
-
}
|
|
295
|
-
formatRelativeTime(e, t, r) {
|
|
296
|
-
const s = new Date(e);
|
|
297
|
-
if (Number.isNaN(s.getTime()))
|
|
298
|
-
return new Intl.RelativeTimeFormat(t, r).format(0, "second");
|
|
299
|
-
const i = Math.floor(((/* @__PURE__ */ new Date()).getTime() - s.getTime()) / 1e3), a = [
|
|
71
|
+
class g {
|
|
72
|
+
formatNumber(e, t, n) {
|
|
73
|
+
return new Intl.NumberFormat(t, n).format(e);
|
|
74
|
+
}
|
|
75
|
+
formatDate(e, t, n) {
|
|
76
|
+
const r = new Date(e);
|
|
77
|
+
return Number.isNaN(r.getTime()) ? "Invalid Date" : new Intl.DateTimeFormat(t, n).format(r);
|
|
78
|
+
}
|
|
79
|
+
formatRelativeTime(e, t, n) {
|
|
80
|
+
const r = new Date(e);
|
|
81
|
+
if (Number.isNaN(r.getTime()))
|
|
82
|
+
return new Intl.RelativeTimeFormat(t, n).format(0, "second");
|
|
83
|
+
const i = Math.floor(((/* @__PURE__ */ new Date()).getTime() - r.getTime()) / 1e3), o = [
|
|
300
84
|
{ unit: "year", seconds: 31536e3 },
|
|
301
85
|
{ unit: "month", seconds: 2592e3 },
|
|
302
86
|
{ unit: "day", seconds: 86400 },
|
|
@@ -304,65 +88,96 @@ class v {
|
|
|
304
88
|
{ unit: "minute", seconds: 60 },
|
|
305
89
|
{ unit: "second", seconds: 1 }
|
|
306
90
|
];
|
|
307
|
-
for (const { unit: l, seconds: u } of
|
|
308
|
-
const
|
|
309
|
-
if (
|
|
310
|
-
return new Intl.RelativeTimeFormat(t,
|
|
91
|
+
for (const { unit: l, seconds: u } of o) {
|
|
92
|
+
const c = Math.floor(i / u);
|
|
93
|
+
if (c >= 1)
|
|
94
|
+
return new Intl.RelativeTimeFormat(t, n).format(-c, l);
|
|
311
95
|
}
|
|
312
|
-
return new Intl.RelativeTimeFormat(t,
|
|
96
|
+
return new Intl.RelativeTimeFormat(t, n).format(0, "second");
|
|
313
97
|
}
|
|
314
98
|
}
|
|
315
|
-
|
|
99
|
+
const m = /\{(\w+)\}/g;
|
|
100
|
+
function d(s, e) {
|
|
101
|
+
return e ? s.replace(m, (t, n) => {
|
|
102
|
+
const r = e[n];
|
|
103
|
+
return r !== void 0 ? String(r) : `{${n}}`;
|
|
104
|
+
}) : s;
|
|
105
|
+
}
|
|
106
|
+
function v(s) {
|
|
107
|
+
return s === "prefix" || s === "prefix_and_default";
|
|
108
|
+
}
|
|
109
|
+
function T(s) {
|
|
110
|
+
return s === "no_prefix";
|
|
111
|
+
}
|
|
112
|
+
function P(s) {
|
|
113
|
+
return s === "prefix";
|
|
114
|
+
}
|
|
115
|
+
function b(s) {
|
|
116
|
+
return s === "prefix_except_default";
|
|
117
|
+
}
|
|
118
|
+
function N(s) {
|
|
119
|
+
return s === "prefix_and_default";
|
|
120
|
+
}
|
|
121
|
+
const p = (s, e, t, n, r) => {
|
|
122
|
+
const a = r(s, t);
|
|
123
|
+
if (!a)
|
|
124
|
+
return null;
|
|
125
|
+
const i = a.toString().split("|");
|
|
126
|
+
if (i.length === 0) return null;
|
|
127
|
+
const o = e < i.length ? i[e] : i[i.length - 1];
|
|
128
|
+
return o ? o.trim().replace("{count}", e.toString()) : null;
|
|
129
|
+
};
|
|
130
|
+
class $ {
|
|
316
131
|
constructor(e = {}) {
|
|
317
|
-
this.formatter = new
|
|
132
|
+
this.formatter = new g(), this.helper = h(e.storage), this.formatter = new g(), this.pluralFunc = e.plural || p, this.missingWarn = e.missingWarn ?? !0, this.missingHandler = e.missingHandler, this.getPreviousPageInfo = e.getPreviousPageInfo, this.getCustomMissingHandler = e.getCustomMissingHandler, this.enablePreviousPageFallback = e.enablePreviousPageFallback ?? !1;
|
|
318
133
|
}
|
|
319
134
|
// --- Public methods (implemented in base class) ---
|
|
320
135
|
/**
|
|
321
136
|
* Get translation for a key
|
|
322
137
|
* Based on logic from src/runtime/plugins/01.plugin.ts
|
|
323
138
|
*/
|
|
324
|
-
t(e, t,
|
|
139
|
+
t(e, t, n, r) {
|
|
325
140
|
if (!e) return "";
|
|
326
|
-
const
|
|
327
|
-
let
|
|
328
|
-
if (!
|
|
141
|
+
const a = this.getLocale(), i = r || this.getRoute();
|
|
142
|
+
let o = this.helper.getTranslation(a, i, e);
|
|
143
|
+
if (!o && this.enablePreviousPageFallback && this.getPreviousPageInfo) {
|
|
329
144
|
const l = this.getPreviousPageInfo();
|
|
330
145
|
if (l) {
|
|
331
146
|
const u = this.helper.getTranslation(l.locale, l.routeName, e);
|
|
332
|
-
u && (
|
|
147
|
+
u && (o = u, process.env.NODE_ENV !== "production" && console.log(`Using fallback translation from previous route: ${l.routeName} -> ${e}`));
|
|
333
148
|
}
|
|
334
149
|
}
|
|
335
|
-
if (!
|
|
150
|
+
if (!o) {
|
|
336
151
|
const l = this.getFallbackLocale();
|
|
337
|
-
|
|
152
|
+
a !== l && (o = this.helper.getTranslation(l, i, e));
|
|
338
153
|
}
|
|
339
|
-
if (!
|
|
154
|
+
if (!o) {
|
|
340
155
|
const l = this.getCustomMissingHandler?.();
|
|
341
|
-
l ? l(
|
|
156
|
+
l ? l(a, e, i) : this.missingHandler ? this.missingHandler(a, e, i) : this.missingWarn && process.env.NODE_ENV !== "production" && typeof window < "u" && console.warn(`Not found '${e}' key in '${a}' locale messages for route '${i}'.`), o = n === void 0 ? e : n || e;
|
|
342
157
|
}
|
|
343
|
-
return typeof
|
|
158
|
+
return typeof o == "string" && t ? d(o, t) : o;
|
|
344
159
|
}
|
|
345
160
|
/**
|
|
346
161
|
* Get translation as string
|
|
347
162
|
*/
|
|
348
|
-
ts(e, t,
|
|
349
|
-
return this.t(e, t,
|
|
163
|
+
ts(e, t, n, r) {
|
|
164
|
+
return this.t(e, t, n, r)?.toString() ?? n ?? e;
|
|
350
165
|
}
|
|
351
166
|
/**
|
|
352
167
|
* Plural translation
|
|
353
168
|
*/
|
|
354
|
-
tc(e, t,
|
|
355
|
-
const { count:
|
|
356
|
-
if (
|
|
357
|
-
return
|
|
358
|
-
const i = (l, u,
|
|
169
|
+
tc(e, t, n) {
|
|
170
|
+
const { count: r, ...a } = typeof t == "number" ? { count: t } : t;
|
|
171
|
+
if (r === void 0)
|
|
172
|
+
return n ?? e;
|
|
173
|
+
const i = (l, u, c) => this.t(l, u, c);
|
|
359
174
|
return this.pluralFunc(
|
|
360
175
|
e,
|
|
361
|
-
Number.parseInt(
|
|
362
|
-
|
|
176
|
+
Number.parseInt(r.toString()),
|
|
177
|
+
a,
|
|
363
178
|
this.getLocale(),
|
|
364
179
|
i
|
|
365
|
-
) ??
|
|
180
|
+
) ?? n ?? e;
|
|
366
181
|
}
|
|
367
182
|
/**
|
|
368
183
|
* Format number
|
|
@@ -387,8 +202,8 @@ class T {
|
|
|
387
202
|
* Based on logic from src/runtime/plugins/01.plugin.ts
|
|
388
203
|
*/
|
|
389
204
|
has(e, t) {
|
|
390
|
-
const
|
|
391
|
-
return !!this.helper.getTranslation(
|
|
205
|
+
const n = t || this.getRoute(), r = this.getLocale();
|
|
206
|
+
return !!this.helper.getTranslation(r, n, e);
|
|
392
207
|
}
|
|
393
208
|
/**
|
|
394
209
|
* Clear cache
|
|
@@ -401,27 +216,26 @@ class T {
|
|
|
401
216
|
* Core translation loading logic (without reactivity)
|
|
402
217
|
* Subclasses can override addTranslations/addRouteTranslations to add reactivity
|
|
403
218
|
*/
|
|
404
|
-
loadTranslationsCore(e, t,
|
|
405
|
-
|
|
219
|
+
loadTranslationsCore(e, t, n) {
|
|
220
|
+
n ? this.helper.mergeGlobalTranslation(e, t, !0) : this.helper.setTranslations(e, t);
|
|
406
221
|
}
|
|
407
222
|
/**
|
|
408
223
|
* Core route translation loading logic (without reactivity)
|
|
409
224
|
* Subclasses can override addRouteTranslations to add reactivity
|
|
410
225
|
*/
|
|
411
|
-
loadRouteTranslationsCore(e, t,
|
|
412
|
-
|
|
226
|
+
loadRouteTranslationsCore(e, t, n, r) {
|
|
227
|
+
r ? this.helper.mergeTranslation(e, t, n, !0) : this.helper.loadPageTranslations(e, t, n);
|
|
413
228
|
}
|
|
414
229
|
}
|
|
415
230
|
export {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
f as withPrefixStrategy
|
|
231
|
+
$ as BaseI18n,
|
|
232
|
+
g as FormatService,
|
|
233
|
+
p as defaultPlural,
|
|
234
|
+
d as interpolate,
|
|
235
|
+
T as isNoPrefixStrategy,
|
|
236
|
+
N as isPrefixAndDefaultStrategy,
|
|
237
|
+
b as isPrefixExceptDefaultStrategy,
|
|
238
|
+
P as isPrefixStrategy,
|
|
239
|
+
h as useTranslationHelper,
|
|
240
|
+
v as withPrefixStrategy
|
|
427
241
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useTranslationHelper, type TranslationStorage } from './translation'
|
|
2
|
-
import { RouteService } from './route-service'
|
|
3
2
|
import { FormatService } from './format-service'
|
|
4
3
|
import { interpolate, withPrefixStrategy, isNoPrefixStrategy, isPrefixStrategy, isPrefixExceptDefaultStrategy, isPrefixAndDefaultStrategy, defaultPlural } from './helpers'
|
|
5
4
|
import { BaseI18n, type BaseI18nOptions } from './base'
|
|
@@ -13,7 +12,6 @@ export {
|
|
|
13
12
|
isPrefixExceptDefaultStrategy,
|
|
14
13
|
isPrefixAndDefaultStrategy,
|
|
15
14
|
defaultPlural,
|
|
16
|
-
RouteService,
|
|
17
15
|
FormatService,
|
|
18
16
|
BaseI18n,
|
|
19
17
|
type TranslationStorage,
|
package/dist/route-service.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { NavigationFailure, RouteLocationAsPathGeneric, RouteLocationNamedRaw, RouteLocationNormalizedLoaded, RouteLocationRaw, RouteLocationResolved, RouteLocationResolvedGeneric, Router } from 'vue-router';
|
|
2
|
-
import { I18nRouteParams, Locale, ModuleOptionsExtend } from '@i18n-micro/types';
|
|
3
|
-
interface NavigateToInterface {
|
|
4
|
-
replace?: boolean;
|
|
5
|
-
redirectCode?: number;
|
|
6
|
-
external?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export type GetDefaultLocale = () => string | null | undefined;
|
|
9
|
-
export declare class RouteService {
|
|
10
|
-
private i18nConfig;
|
|
11
|
-
private router;
|
|
12
|
-
private hashLocaleDefault;
|
|
13
|
-
private noPrefixDefault;
|
|
14
|
-
private navigateTo;
|
|
15
|
-
/** Optional getter for current locale (used by hash/noPrefix when state changes). Plugin provides () => localeState.value */
|
|
16
|
-
private getDefaultLocale?;
|
|
17
|
-
constructor(i18nConfig: ModuleOptionsExtend, router: Router, hashLocaleDefault: string | null | undefined, noPrefixDefault: string | null | undefined, navigateTo: (to: RouteLocationRaw | undefined | null, options?: NavigateToInterface) => Promise<void | NavigationFailure | false> | false | void | RouteLocationRaw,
|
|
18
|
-
/** Optional getter for current locale (used by hash/noPrefix when state changes). Plugin provides () => localeState.value */
|
|
19
|
-
getDefaultLocale?: GetDefaultLocale | undefined);
|
|
20
|
-
/**
|
|
21
|
-
* Extracts locale from URL path by checking the first path segment
|
|
22
|
-
* @param path - URL path (e.g., '/ru/sdfsdf' or '/en/about')
|
|
23
|
-
* @returns Locale code or null if not found
|
|
24
|
-
*/
|
|
25
|
-
private extractLocaleFromPath;
|
|
26
|
-
getCurrentLocale(route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric): string;
|
|
27
|
-
getCurrentName(route: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric): string | null;
|
|
28
|
-
getRouteName(route: RouteLocationResolvedGeneric | RouteLocationNamedRaw, locale: string): string;
|
|
29
|
-
getPluginRouteName(route: RouteLocationResolvedGeneric | RouteLocationNamedRaw, locale: string): string;
|
|
30
|
-
getFullPathWithBaseUrl(currentLocale: Locale, route: RouteLocationRaw): string;
|
|
31
|
-
switchLocaleRoute(fromLocale: string, toLocale: string, route: RouteLocationResolvedGeneric | RouteLocationNamedRaw, i18nRouteParams: I18nRouteParams): RouteLocationRaw;
|
|
32
|
-
private resolveParams;
|
|
33
|
-
private handlePrefixStrategy;
|
|
34
|
-
private createLocalizedRoute;
|
|
35
|
-
getLocalizedRoute(to: RouteLocationResolvedGeneric | RouteLocationAsPathGeneric | RouteLocationNamedRaw | string, route: RouteLocationNormalizedLoaded, locale?: string): RouteLocationResolved;
|
|
36
|
-
getCurrentRoute(): RouteLocationNormalizedLoaded;
|
|
37
|
-
private resolveRouteWithStrategy;
|
|
38
|
-
switchLocaleLogic(toLocale: string, i18nRouteParams: I18nRouteParams, to?: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string): string | false | void | import('vue-router').RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric | Promise<false | void | NavigationFailure>;
|
|
39
|
-
resolveLocalizedRoute(to: RouteLocationNamedRaw | RouteLocationAsPathGeneric | string, locale?: string): RouteLocationResolved;
|
|
40
|
-
}
|
|
41
|
-
export {};
|