@i18n-micro/vue 1.3.0 → 1.3.2
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.mjs +202 -180
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("vue"),E=require("@i18n-micro/core"),Z=require("vue-router"),I=Symbol("i18n"),N=Symbol("i18n-locales"),U=Symbol("i18n-default-locale"),$=Symbol("i18n-router-strategy"),F=a.defineComponent({name:"I18nGroup",props:{prefix:{type:String,required:!0},groupClass:{type:String,default:""}},setup(t,{slots:e}){const r=a.inject(I);if(!r)throw new Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");const o=(u,l)=>r.t(`${t.prefix}.${u}`,l,void 0,r.getRoute());return()=>a.h("div",{class:["i18n-group",t.groupClass]},e.default?.({prefix:t.prefix,t:o}))}}),W=a.defineComponent({name:"I18nLink",props:{to:{type:[String,Object],required:!0},activeStyle:{type:Object,default:()=>({})},localeRoute:{type:Function,default:void 0}},setup(t,{slots:e}){const r=a.inject(I),o=a.inject($,void 0);if(!r)throw new Error("[i18n-micro] I18nLink: i18n instance not found. Make sure i18n plugin is installed.");const u=a.computed(()=>typeof t.to=="string"?/^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to):!1),l=a.computed(()=>{if(u.value)return t.to;if(t.localeRoute){const n=t.localeRoute(t.to);return typeof n=="string"?n:n.path||"/"}if(!o?.resolvePath)return typeof t.to=="string"?t.to:t.to.path||"/";const i=o.resolvePath(t.to,r.locale.value);return typeof i=="string"?i:i.path||"/"}),d=a.computed(()=>{if(u.value||!o)return!1;const i=o.getCurrentPath().replace(/\/$/,""),n=l.value.replace(/\/$/,"");return i===n}),h=a.computed(()=>d.value?t.activeStyle:{});return()=>u.value?a.h("a",{href:l.value,target:"_blank",rel:"noopener noreferrer",style:h.value},e.default?.()):o?.linkComponent?a.h(o.linkComponent,{to:l.value,style:h.value},{default:e.default}):a.h("a",{href:l.value,style:h.value,onClick:i=>{i.preventDefault(),o?o.push({path:l.value}):window.location.href=l.value}},e.default?.())}}),q=a.defineComponent({name:"I18nSwitcher",props:{customLabels:{type:Object,default:()=>({})},customWrapperStyle:{type:Object,default:()=>({})},customButtonStyle:{type:Object,default:()=>({})},customDropdownStyle:{type:Object,default:()=>({})},customItemStyle:{type:Object,default:()=>({})},customLinkStyle:{type:Object,default:()=>({})},customActiveLinkStyle:{type:Object,default:()=>({})},customDisabledLinkStyle:{type:Object,default:()=>({})},customIconStyle:{type:Object,default:()=>({})},locales:{type:Array,default:void 0},currentLocale:{type:[String,Function],default:void 0},getLocaleName:{type:Function,default:void 0},switchLocale:{type:Function,default:void 0},localeRoute:{type:Function,default:void 0}},setup(t,{slots:e}){const r=a.inject(I),o=a.inject($,void 0),u=a.inject(N,void 0);if(!r)throw new Error("[i18n-micro] I18nSwitcher: i18n instance not found. Make sure i18n plugin is installed.");if(!u&&!t.locales)throw new Error("[i18n-micro] I18nSwitcher: locales not provided. Make sure app.provide(I18nLocalesKey, locales) is called or pass locales prop.");const l=a.computed(()=>t.locales||u||[]),d=a.computed(()=>t.currentLocale!==void 0?typeof t.currentLocale=="function"?t.currentLocale():t.currentLocale:r.locale.value),h=a.computed(()=>t.getLocaleName?t.getLocaleName()||null:l.value.find(y=>y.code===r.locale.value)?.displayName||null),i=a.ref(!1),n=a.ref(null),c=s=>{s&&(s.stopPropagation(),s.preventDefault()),i.value=!i.value},f=s=>t.customLabels[s.code]||s.displayName||s.code,m=a.computed(()=>{const s=l.value.find(y=>y.code===d.value);return s?f(s):h.value||d.value}),k=async s=>{if(i.value=!1,await a.nextTick(),t.switchLocale){t.switchLocale(s);return}if(r.locale.value=s,!o)return;const y=o.getCurrentPath(),b=t.localeRoute?(()=>{const g=t.localeRoute(y,s);return typeof g=="string"?g:g.path||"/"})():o?.resolvePath?(()=>{const g=o.resolvePath(y,s);return typeof g=="string"?g:g.path||"/"})():y;o.push({path:b})},S={position:"relative",display:"inline-block",verticalAlign:"middle"},P={padding:"4px 12px",fontSize:"16px",cursor:"pointer",backgroundColor:"#fff",border:"1px solid #333",transition:"background-color 0.3s ease",display:"flex",alignItems:"center",justifyContent:"space-between"},R={position:"absolute",top:"100%",left:"0",zIndex:1e3,backgroundColor:"#fff",border:"1px solid #333",listStyle:"none",padding:"0",margin:"4px 0 0 0",minWidth:"150px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},j={margin:"0",padding:"0"},L={display:"block",padding:"8px 12px",color:"#333",textDecoration:"none",transition:"background-color 0.3s ease",cursor:"pointer"},K={fontWeight:"bold",color:"#007bff"},D={marginLeft:"8px",display:"inline-block",transition:"transform 0.3s ease"},M={transform:"rotate(180deg)"},v=s=>s?Array.isArray(s)?s:[s]:[],H=s=>{if(!i.value)return;const y=s.target;if(!y||!n.value)return;const b=n.value.contains(y),g=y.closest(".i18n-switcher-button")!==null;!b&&!g&&(i.value=!1)};return a.onMounted(()=>{document.addEventListener("click",H)}),a.onUnmounted(()=>{document.removeEventListener("click",H)}),()=>{const s=[];e["before-button"]&&s.push(...v(e["before-button"]()));const y=[];if(e["before-selected-locale"]&&y.push(...v(e["before-selected-locale"]())),y.push(a.h("span",m.value)),e["after-selected-locale"]&&y.push(...v(e["after-selected-locale"]())),y.push(a.h("span",{style:{...D,...i.value?M:{},...t.customIconStyle}},"▼")),s.push(a.h("button",{class:"i18n-switcher-button",style:{...P,...t.customButtonStyle},onClick:b=>{b.preventDefault(),b.stopPropagation(),c(b)},type:"button",ariaHaspopup:!0,ariaExpanded:i.value},y)),e["before-dropdown"]&&s.push(...v(e["before-dropdown"]())),i.value){const b=[];e["before-dropdown-items"]&&b.push(...v(e["before-dropdown-items"]())),l.value.forEach(g=>{const C=[];e["before-item"]&&C.push(...v(e["before-item"]({locale:g})));const T=[];e["before-link-content"]&&T.push(...v(e["before-link-content"]({locale:g}))),T.push(f(g)),e["after-link-content"]&&T.push(...v(e["after-link-content"]({locale:g})));const x=typeof window<"u"?window.location.pathname:"/",p=t.localeRoute?t.localeRoute(x,g.code):o?.resolvePath?o.resolvePath(x,g.code):x,_=typeof p=="string"?p:p.path||"#",O=g.code===d.value;C.push(a.h("a",{class:`switcher-locale-${g.code}`,href:typeof _=="string"?_:"#",style:{...L,...O?K:{},...t.customLinkStyle},onClick:w=>{w.preventDefault(),w.stopPropagation(),k(g.code)}},T)),e["after-item"]&&C.push(...v(e["after-item"]({locale:g}))),b.push(a.h("li",{key:g.code,style:{...j,...t.customItemStyle}},C))}),e["after-dropdown-items"]&&b.push(...v(e["after-dropdown-items"]())),s.push(a.h("ul",{class:"i18n-switcher-dropdown",style:{...R,...t.customDropdownStyle}},b))}return e["after-dropdown"]&&s.push(...v(e["after-dropdown"]())),a.h("div",{ref:n,class:"i18n-switcher-wrapper",style:{...S,...t.customWrapperStyle}},s)}}}),B=a.defineComponent({name:"I18nT",props:{keypath:{type:String,required:!0},plural:{type:[Number,String]},tag:{type:String,default:"span"},params:{type:Object,default:()=>({})},defaultValue:{type:String,default:""},html:{type:Boolean,default:!1},hideIfEmpty:{type:Boolean,default:!1},customPluralRule:{type:Function,default:null},number:{type:[Number,String]},date:{type:[Date,String,Number]},relativeDate:{type:[Date,String,Number]}},setup(t,{slots:e,attrs:r}){const o=a.inject(I);if(!o)throw new Error("[i18n-micro] I18nT: i18n instance not found. Make sure i18n plugin is installed.");return()=>{const u={},l=o.getRoute();if(t.number!==void 0){const n=Number(t.number),c=o.tn(n),f=o.t(t.keypath,{number:c,...t.params},void 0,l);return a.h(t.tag,{...r,innerHTML:f})}if(t.date!==void 0){const n=o.td(t.date),c=o.t(t.keypath,{date:n,...t.params},void 0,l);return a.h(t.tag,{...r,innerHTML:c})}if(t.relativeDate!==void 0){const n=o.tdr(t.relativeDate),c=o.t(t.keypath,{relativeDate:n,...t.params},void 0,l);return a.h(t.tag,{...r,innerHTML:c})}if(t.plural!==void 0){const n=Number.parseInt(t.plural.toString(),10);if(t.customPluralRule){const c=t.customPluralRule(t.keypath,n,t.params,o.locale.value,(f,m,k)=>o.t(f,m,k,l));return a.h(t.tag,{...r,innerHTML:c||""})}else{const c=o.tc(t.keypath,{count:n,...t.params});return a.h(t.tag,{...r,innerHTML:c})}}const d=(o.t(t.keypath,{...t.params,...u},void 0,l)??"").toString();if(t.hideIfEmpty&&!d.trim())return t.defaultValue??null;if(t.html)return a.h(t.tag,{...r,innerHTML:d});if(e.default)return a.h(t.tag,r,e.default({translation:d}));const h=[];let i=0;for(const[n,c]of Object.entries(e)){if(n==="default")continue;const f=`{${n}}`,m=d.indexOf(f,i);m!==-1&&(m>i&&h.push(d.slice(i,m)),c&&h.push(a.h(c)),i=m+f.length)}return i<d.length&&h.push(d.slice(i)),e.default?a.h(t.tag,r,e.default({children:h})):h.length>0?a.h(t.tag,r,h):a.h(t.tag,r,d)}}});function z(t){const e=a.inject(I),r=a.inject($,void 0),o=a.inject(N,void 0),u=a.inject(U,void 0);if(!e)throw new Error("[i18n-micro] useI18n() must be called after app.use(i18n). Make sure i18n plugin is installed.");if(!o)throw new Error("[i18n-micro] I18nLocalesKey not provided. Make sure app.provide(I18nLocalesKey, locales) is called.");if(!u)throw new Error("[i18n-micro] I18nDefaultLocaleKey not provided. Make sure app.provide(I18nDefaultLocaleKey, defaultLocale) is called.");const l=t?.locales||o,d=t?.defaultLocale||u,h=(i,n)=>r?.resolvePath?r.resolvePath(i,n||e.locale.value):i;return{instance:e,locale:a.computed({get:()=>e.locale.value,set:i=>{e.locale.value=i}}),getLocales:()=>l,defaultLocale:()=>d,getLocaleName:()=>l.find(n=>n.code===e.locale.value)?.displayName||null,localeRoute:h,localePath:(i,n)=>{const c=h(i,n);return typeof c=="string"?c:c.path||"/"},switchLocale:i=>{if(e.locale.value=i,r){const n=r.getCurrentPath(),c=h(n,i);r.push(typeof c=="string"?{path:c}:{path:c.path||"/"})}},t:e.t.bind(e),ts:e.ts.bind(e),tc:e.tc.bind(e),tn:e.tn.bind(e),td:e.td.bind(e),tdr:e.tdr.bind(e),has:e.has.bind(e),setRoute:e.setRoute.bind(e),getRoute:e.getRoute.bind(e),getLocale:()=>e.locale.value,addTranslations:e.addTranslations.bind(e),addRouteTranslations:e.addRouteTranslations.bind(e),mergeTranslations:e.mergeTranslations.bind(e),clearCache:e.clearCache.bind(e)}}function J(t={}){const{addDirAttribute:e=!0,identifierAttribute:r="id",addSeoAttributes:o=!0,baseUrl:u="/"}=t,{getLocale:l,getLocales:d,localeRoute:h}=z(),i=a.inject($,void 0),n=a.ref({htmlAttrs:{},link:[],meta:[]});function c(m,k){const S=new URL(m,"http://localhost"),P=new URLSearchParams(S.search),R={};for(const L of k)P.has(L)&&(R[L]=P.get(L));const j=new URLSearchParams(R);return j.toString()?`${S.pathname}?${j.toString()}`:S.pathname}function f(m=[]){if(!i){n.value={htmlAttrs:{},link:[],meta:[]};return}const k=l(),S=d(),P=S.find(p=>p.code===k);if(!P)return;const R=P.iso||k,j=P.dir||"auto";let L=i.getCurrentPath();L.startsWith("/")||(L=`/${L}`);const K=L.split("/").filter(Boolean),D=S.find(p=>K[0]===p.code);let M=L,v;D?(M=L.slice(D.code.length+1)||"/",v=c(M,m)):v=c(L,m);const s=`${typeof u=="function"?u():u}${v.startsWith("/")?"":"/"}${v}`;if(n.value={htmlAttrs:{lang:R,...e?{dir:j}:{}},link:[],meta:[]},!o)return;const y=S,b={[r]:"i18n-og",property:"og:locale",content:R},g={[r]:"i18n-og-url",property:"og:url",content:s},C=y.map(p=>({[r]:`i18n-og-alt-${p.iso||p.code}`,property:"og:locale:alternate",content:p.iso||p.code})),T={[r]:"i18n-can",rel:"canonical",href:s},x=y.flatMap(p=>{if(!h||!i)return[];const _=i.getCurrentPath(),O=h(_,p.code),w=typeof O=="string"?O:O?.path||"/";if(!w)return[];let A;w.startsWith("http://")||w.startsWith("https://")?A=w:A=`${typeof u=="function"?u():u}${w.startsWith("/")?"":"/"}${w}`;const V=[{[r]:`i18n-alternate-${p.code}`,rel:"alternate",href:A,hreflang:p.code}];return p.iso&&p.iso!==p.code&&V.push({[r]:`i18n-alternate-${p.iso}`,rel:"alternate",href:A,hreflang:p.iso}),V});n.value.meta=[b,g,...C],n.value.link=[T,...x]}return{metaObject:n,updateMeta:f}}class G extends E.BaseI18n{constructor(e){const r={translations:new Map};if(super({storage:r,plural:e.plural,missingWarn:e.missingWarn,missingHandler:e.missingHandler}),this.listeners=new Set,this.storage=r,this._locale=a.shallowRef(e.locale),this._fallbackLocale=a.shallowRef(e.fallbackLocale||e.locale),this._currentRoute=a.shallowRef("index"),this._revision=a.shallowRef(0),e.messages)for(const[o,u]of Object.entries(e.messages))this.helper.loadTranslations(o,u)}get locale(){return this._locale}set locale(e){typeof e=="string"?this._locale.value=e:this._locale=e}get fallbackLocale(){return this._fallbackLocale}set fallbackLocale(e){typeof e=="string"?this._fallbackLocale.value=e:this._fallbackLocale=e}get currentRoute(){return this._currentRoute}setRoute(e){this._currentRoute.value=e}getLocale(){return this._locale.value}getFallbackLocale(){return this._fallbackLocale.value}getRoute(){return this._currentRoute.value}addTranslations(e,r,o=!0){super.loadTranslationsCore(e,r,o),this._revision.value++,this.notifyListeners()}addRouteTranslations(e,r,o,u=!0){super.loadRouteTranslationsCore(e,r,o,u),this._revision.value++,this.notifyListeners()}mergeTranslations(e,r,o){this.helper.mergeTranslation(e,r,o,!0),this._revision.value++,this.notifyListeners()}clearCache(){super.clearCache(),this._revision.value++,this.notifyListeners()}subscribeToChanges(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notifyListeners(){this.listeners.forEach(e=>e())}getAllTranslations(){const e={};for(const[r,o]of this.storage.translations)if(!r.includes(":"))e[r]=o;else{const u=r.split(":")[0];u&&(e[u]||(e[u]={}),Object.assign(e[u],o))}return e}getStorage(){return this.storage}getRouteCache(){const e={};for(const[r,o]of this.storage.translations)e[r]=o;return e}}function Q(t){const{routingStrategy:e,locales:r,defaultLocale:o,...u}=t,l=new G(u);let d=null,h=e||null;return{global:l,setRoutingStrategy:n=>{h=n,d&&d.provide($,n)},install(n){d=n,n.provide(I,l),h&&n.provide($,h),r&&n.provide(N,r),o&&n.provide(U,o),n.config.globalProperties.$t=(c,f,m,k)=>l.t(c,f,m,k),n.config.globalProperties.$ts=(c,f,m,k)=>l.ts(c,f,m,k),n.config.globalProperties.$tc=(c,f,m)=>l.tc(c,f,m),n.config.globalProperties.$tn=(c,f)=>l.tn(c,f),n.config.globalProperties.$td=(c,f)=>l.td(c,f),n.config.globalProperties.$tdr=(c,f)=>l.tdr(c,f),n.config.globalProperties.$has=(c,f)=>l.has(c,f),n.config.globalProperties.$i18n=l,n.component("I18nT",B),n.component("I18nLink",W),n.component("I18nGroup",F),n.component("I18nSwitcher",q)}}}function X(t,e,r){const o=e.map(l=>l.code),u=(l,d)=>{const i=(typeof l=="string"?l:l.path||"/").split("/").filter(Boolean),n=i[0];n!==void 0&&o.includes(n)&&i.shift();const c=`/${i.join("/")}`;return d===r?c:`/${d}${c==="/"?"":c}`};return{linkComponent:Z.RouterLink,getCurrentPath:()=>t.currentRoute.value.path,push:l=>{t.push(l.path).catch(()=>{})},replace:l=>{t.replace(l.path).catch(()=>{})},resolvePath:(l,d)=>u(l,d),getRoute:()=>({fullPath:t.currentRoute.value.fullPath,query:t.currentRoute.value.query})}}Object.defineProperty(exports,"FormatService",{enumerable:!0,get:()=>E.FormatService});Object.defineProperty(exports,"defaultPlural",{enumerable:!0,get:()=>E.defaultPlural});Object.defineProperty(exports,"interpolate",{enumerable:!0,get:()=>E.interpolate});exports.I18nDefaultLocaleKey=U;exports.I18nGroup=F;exports.I18nInjectionKey=I;exports.I18nLink=W;exports.I18nLocalesKey=N;exports.I18nSwitcher=q;exports.I18nT=B;exports.VueI18n=G;exports.createI18n=Q;exports.createVueRouterAdapter=X;exports.useI18n=z;exports.useLocaleHead=J;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("vue"),U=require("@i18n-micro/core"),Y=require("vue-router"),T=Symbol("i18n"),V=Symbol("i18n-locales"),F=Symbol("i18n-default-locale"),A=Symbol("i18n-router-strategy"),z=a.defineComponent({name:"I18nGroup",props:{prefix:{type:String,required:!0},groupClass:{type:String,default:""}},setup(t,{slots:e}){const r=a.inject(T);if(!r)throw new Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");const o=(u,l)=>r.t(`${t.prefix}.${u}`,l,void 0,r.getRoute());return()=>a.h("div",{class:["i18n-group",t.groupClass]},e.default?.({prefix:t.prefix,t:o}))}}),G=a.defineComponent({name:"I18nLink",props:{to:{type:[String,Object],required:!0},activeStyle:{type:Object,default:()=>({})},localeRoute:{type:Function,default:void 0}},setup(t,{slots:e}){const r=a.inject(T),o=a.inject(A,void 0);if(!r)throw new Error("[i18n-micro] I18nLink: i18n instance not found. Make sure i18n plugin is installed.");const u=a.computed(()=>typeof t.to=="string"?/^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to):!1),l=a.computed(()=>{if(u.value)return t.to;if(t.localeRoute){const n=t.localeRoute(t.to);return typeof n=="string"?n:n.path||"/"}if(!o?.resolvePath)return typeof t.to=="string"?t.to:t.to.path||"/";const i=o.resolvePath(t.to,r.locale.value);return typeof i=="string"?i:i.path||"/"}),d=a.computed(()=>{if(u.value||!o)return!1;const i=o.getCurrentPath().replace(/\/$/,""),n=l.value.replace(/\/$/,"");return i===n}),h=a.computed(()=>d.value?t.activeStyle:{});return()=>u.value?a.h("a",{href:l.value,target:"_blank",rel:"noopener noreferrer",style:h.value},e.default?.()):o?.linkComponent?a.h(o.linkComponent,{to:l.value,style:h.value},{default:e.default}):a.h("a",{href:l.value,style:h.value,onClick:i=>{i.preventDefault(),o?o.push({path:l.value}):window.location.href=l.value}},e.default?.())}}),Z=a.defineComponent({name:"I18nSwitcher",props:{customLabels:{type:Object,default:()=>({})},customWrapperStyle:{type:Object,default:()=>({})},customButtonStyle:{type:Object,default:()=>({})},customDropdownStyle:{type:Object,default:()=>({})},customItemStyle:{type:Object,default:()=>({})},customLinkStyle:{type:Object,default:()=>({})},customActiveLinkStyle:{type:Object,default:()=>({})},customDisabledLinkStyle:{type:Object,default:()=>({})},customIconStyle:{type:Object,default:()=>({})},locales:{type:Array,default:void 0},currentLocale:{type:[String,Function],default:void 0},getLocaleName:{type:Function,default:void 0},switchLocale:{type:Function,default:void 0},localeRoute:{type:Function,default:void 0}},setup(t,{slots:e}){const r=a.inject(T),o=a.inject(A,void 0),u=a.inject(V,void 0);if(!r)throw new Error("[i18n-micro] I18nSwitcher: i18n instance not found. Make sure i18n plugin is installed.");if(!u&&!t.locales)throw new Error("[i18n-micro] I18nSwitcher: locales not provided. Make sure app.provide(I18nLocalesKey, locales) is called or pass locales prop.");const l=a.computed(()=>t.locales||u||[]),d=a.computed(()=>t.currentLocale!==void 0?typeof t.currentLocale=="function"?t.currentLocale():t.currentLocale:r.locale.value),h=a.computed(()=>t.getLocaleName?t.getLocaleName()||null:l.value.find(y=>y.code===r.locale.value)?.displayName||null),i=a.ref(!1),n=a.ref(null),c=s=>{s&&(s.stopPropagation(),s.preventDefault()),i.value=!i.value},g=s=>t.customLabels[s.code]||s.displayName||s.code,m=a.computed(()=>{const s=l.value.find(y=>y.code===d.value);return s?g(s):h.value||d.value}),b=async s=>{if(i.value=!1,await a.nextTick(),t.switchLocale){t.switchLocale(s);return}if(r.locale.value=s,!o)return;const y=o.getCurrentPath(),v=t.localeRoute?(()=>{const p=t.localeRoute(y,s);return typeof p=="string"?p:p.path||"/"})():o?.resolvePath?(()=>{const p=o.resolvePath(y,s);return typeof p=="string"?p:p.path||"/"})():y;o.push({path:v})},k={position:"relative",display:"inline-block",verticalAlign:"middle"},P={padding:"4px 12px",fontSize:"16px",cursor:"pointer",backgroundColor:"#fff",border:"1px solid #333",transition:"background-color 0.3s ease",display:"flex",alignItems:"center",justifyContent:"space-between"},C={position:"absolute",top:"100%",left:"0",zIndex:1e3,backgroundColor:"#fff",border:"1px solid #333",listStyle:"none",padding:"0",margin:"4px 0 0 0",minWidth:"150px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},O={margin:"0",padding:"0"},$={display:"block",padding:"8px 12px",color:"#333",textDecoration:"none",transition:"background-color 0.3s ease",cursor:"pointer"},R={fontWeight:"bold",color:"#007bff"},q={marginLeft:"8px",display:"inline-block",transition:"transform 0.3s ease"},H={transform:"rotate(180deg)"},L=s=>s?Array.isArray(s)?s:[s]:[],I=s=>{if(!i.value)return;const y=s.target;if(!y||!n.value)return;const v=n.value.contains(y),p=y.closest(".i18n-switcher-button")!==null;!v&&!p&&(i.value=!1)};return a.onMounted(()=>{document.addEventListener("click",I)}),a.onUnmounted(()=>{document.removeEventListener("click",I)}),()=>{const s=[];e["before-button"]&&s.push(...L(e["before-button"]()));const y=[];if(e["before-selected-locale"]&&y.push(...L(e["before-selected-locale"]())),y.push(a.h("span",m.value)),e["after-selected-locale"]&&y.push(...L(e["after-selected-locale"]())),y.push(a.h("span",{style:{...q,...i.value?H:{},...t.customIconStyle}},"▼")),s.push(a.h("button",{class:"i18n-switcher-button",style:{...P,...t.customButtonStyle},onClick:v=>{v.preventDefault(),v.stopPropagation(),c(v)},type:"button",ariaHaspopup:!0,ariaExpanded:i.value},y)),e["before-dropdown"]&&s.push(...L(e["before-dropdown"]())),i.value){const v=[];e["before-dropdown-items"]&&v.push(...L(e["before-dropdown-items"]())),l.value.forEach(p=>{const D=[];e["before-item"]&&D.push(...L(e["before-item"]({locale:p})));const M=[];e["before-link-content"]&&M.push(...L(e["before-link-content"]({locale:p}))),M.push(g(p)),e["after-link-content"]&&M.push(...L(e["after-link-content"]({locale:p})));const _=typeof window<"u"?window.location.pathname:"/",E=t.localeRoute?t.localeRoute(_,p.code):o?.resolvePath?o.resolvePath(_,p.code):_,x=typeof E=="string"?E:E.path||"#",N=p.code===d.value;D.push(a.h("a",{class:`switcher-locale-${p.code}`,href:typeof x=="string"?x:"#",style:{...$,...N?R:{},...t.customLinkStyle},onClick:K=>{K.preventDefault(),K.stopPropagation(),b(p.code)}},M)),e["after-item"]&&D.push(...L(e["after-item"]({locale:p}))),v.push(a.h("li",{key:p.code,style:{...O,...t.customItemStyle}},D))}),e["after-dropdown-items"]&&v.push(...L(e["after-dropdown-items"]())),s.push(a.h("ul",{class:"i18n-switcher-dropdown",style:{...C,...t.customDropdownStyle}},v))}return e["after-dropdown"]&&s.push(...L(e["after-dropdown"]())),a.h("div",{ref:n,class:"i18n-switcher-wrapper",style:{...k,...t.customWrapperStyle}},s)}}}),J=a.defineComponent({name:"I18nT",props:{keypath:{type:String,required:!0},plural:{type:[Number,String]},tag:{type:String,default:"span"},params:{type:Object,default:()=>({})},defaultValue:{type:String,default:""},html:{type:Boolean,default:!1},hideIfEmpty:{type:Boolean,default:!1},customPluralRule:{type:Function,default:null},number:{type:[Number,String]},date:{type:[Date,String,Number]},relativeDate:{type:[Date,String,Number]}},setup(t,{slots:e,attrs:r}){const o=a.inject(T);if(!o)throw new Error("[i18n-micro] I18nT: i18n instance not found. Make sure i18n plugin is installed.");return()=>{const u={},l=o.getRoute();if(t.number!==void 0){const n=Number(t.number),c=o.tn(n),g=o.t(t.keypath,{number:c,...t.params},void 0,l);return a.h(t.tag,{...r,innerHTML:g})}if(t.date!==void 0){const n=o.td(t.date),c=o.t(t.keypath,{date:n,...t.params},void 0,l);return a.h(t.tag,{...r,innerHTML:c})}if(t.relativeDate!==void 0){const n=o.tdr(t.relativeDate),c=o.t(t.keypath,{relativeDate:n,...t.params},void 0,l);return a.h(t.tag,{...r,innerHTML:c})}if(t.plural!==void 0){const n=Number.parseInt(t.plural.toString(),10);if(t.customPluralRule){const c=t.customPluralRule(t.keypath,n,t.params,o.locale.value,(g,m,b)=>o.t(g,m,b,l));return a.h(t.tag,{...r,innerHTML:c||""})}else{const c=o.tc(t.keypath,{count:n,...t.params});return a.h(t.tag,{...r,innerHTML:c})}}const d=(o.t(t.keypath,{...t.params,...u},void 0,l)??"").toString();if(t.hideIfEmpty&&!d.trim())return t.defaultValue??null;if(t.html)return a.h(t.tag,{...r,innerHTML:d});if(e.default)return a.h(t.tag,r,e.default({translation:d}));const h=[];let i=0;for(const[n,c]of Object.entries(e)){if(n==="default")continue;const g=`{${n}}`,m=d.indexOf(g,i);m!==-1&&(m>i&&h.push(d.slice(i,m)),c&&h.push(a.h(c)),i=m+g.length)}return i<d.length&&h.push(d.slice(i)),e.default?a.h(t.tag,r,e.default({children:h})):h.length>0?a.h(t.tag,r,h):a.h(t.tag,r,d)}}});function Q(t){const e=a.inject(T),r=a.inject(A,void 0),o=a.inject(V,void 0),u=a.inject(F,void 0);if(!e)throw new Error("[i18n-micro] useI18n() must be called after app.use(i18n). Make sure i18n plugin is installed.");if(!o)throw new Error("[i18n-micro] I18nLocalesKey not provided. Make sure app.provide(I18nLocalesKey, locales) is called.");if(!u)throw new Error("[i18n-micro] I18nDefaultLocaleKey not provided. Make sure app.provide(I18nDefaultLocaleKey, defaultLocale) is called.");const l=t?.locales||o,d=t?.defaultLocale||u,h=(i,n)=>r?.resolvePath?r.resolvePath(i,n||e.locale.value):i;return{instance:e,locale:a.computed({get:()=>e.locale.value,set:i=>{e.locale.value=i}}),getLocales:()=>l,defaultLocale:()=>d,getLocaleName:()=>l.find(n=>n.code===e.locale.value)?.displayName||null,localeRoute:h,localePath:(i,n)=>{const c=h(i,n);return typeof c=="string"?c:c.path||"/"},switchLocale:i=>{if(e.locale.value=i,r){const n=r.getCurrentPath(),c=h(n,i);r.push(typeof c=="string"?{path:c}:{path:c.path||"/"})}},t:e.t.bind(e),ts:e.ts.bind(e),tc:e.tc.bind(e),tn:e.tn.bind(e),td:e.td.bind(e),tdr:e.tdr.bind(e),has:e.has.bind(e),setRoute:e.setRoute.bind(e),getRoute:e.getRoute.bind(e),getLocale:()=>e.locale.value,addTranslations:e.addTranslations.bind(e),addRouteTranslations:e.addRouteTranslations.bind(e),mergeTranslations:e.mergeTranslations.bind(e),clearCache:e.clearCache.bind(e)}}function ee(t={}){const{addDirAttribute:e=!0,identifierAttribute:r="id",addSeoAttributes:o=!0,baseUrl:u="/"}=t,{getLocale:l,getLocales:d,localeRoute:h}=Q(),i=a.inject(A,void 0),n=a.ref({htmlAttrs:{},link:[],meta:[]});function c(m,b){const k=new URL(m,"http://localhost"),P=new URLSearchParams(k.search),C={};for(const $ of b)P.has($)&&(C[$]=P.get($));const O=new URLSearchParams(C);return O.toString()?`${k.pathname}?${O.toString()}`:k.pathname}function g(m=[]){if(!i){n.value={htmlAttrs:{},link:[],meta:[]};return}const b=l(),k=d(),P=k.find(f=>f.code===b);if(!P)return;const C=P.iso||b,O=P.og||C,$=P.dir||"auto";let R=i.getCurrentPath();R.startsWith("/")||(R=`/${R}`);const q=R.split("/").filter(Boolean),H=k.find(f=>q[0]===f.code);let L=R,I,s;const y=typeof u=="function"?u():u;if(H){L=R.slice(H.code.length+1)||"/",I=c(L,m);const f=`/${b}`;s=`${y}${f}${I.startsWith("/")?"":"/"}${I}`}else I=c(R,m),s=`${y}${I.startsWith("/")?"":"/"}${I}`;if(n.value={htmlAttrs:{lang:C,...e?{dir:$}:{}},link:[],meta:[]},!o)return;const v=k.filter(f=>!f.disabled&&f.seo!==!1),p={[r]:"i18n-og",property:"og:locale",content:O},D={[r]:"i18n-og-url",property:"og:url",content:s},M=v.filter(f=>f.code!==b).map(f=>{const j=f.og||f.iso||f.code;return{[r]:`i18n-og-alt-${j}`,property:"og:locale:alternate",content:j}}),_={[r]:"i18n-can",rel:"canonical",href:s},E=v.flatMap(f=>{if(!h||!i)return[];const j=i.getCurrentPath(),S=h(j,f.code),w=typeof S=="string"?S:S?.path||"/";if(!w)return[];let W;w.startsWith("http://")||w.startsWith("https://")?W=w:W=`${typeof u=="function"?u():u}${w.startsWith("/")?"":"/"}${w}`;const B=[{[r]:`i18n-alternate-${f.code}`,rel:"alternate",href:W,hreflang:f.code}];return f.iso&&f.iso!==f.code&&B.push({[r]:`i18n-alternate-${f.iso}`,rel:"alternate",href:W,hreflang:f.iso}),B}),x=a.inject(F,void 0);let N=null;const K=x?k.find(f=>f.code===x):void 0;if(h&&i&&x&&K?.seo!==!1){const f=i.getCurrentPath(),j=h(f,x),S=typeof j=="string"?j:j?.path||"/";if(S){let w;S.startsWith("http://")||S.startsWith("https://")?w=S:w=`${typeof u=="function"?u():u}${S.startsWith("/")?"":"/"}${S}`,N={[r]:"i18n-xd",rel:"alternate",href:w,hreflang:"x-default"}}}n.value.meta=[p,D,...M],n.value.link=[_,...E,...N?[N]:[]]}return{metaObject:n,updateMeta:g}}class X extends U.BaseI18n{constructor(e){const r={translations:new Map};if(super({storage:r,plural:e.plural,missingWarn:e.missingWarn,missingHandler:e.missingHandler}),this.listeners=new Set,this.storage=r,this._locale=a.shallowRef(e.locale),this._fallbackLocale=a.shallowRef(e.fallbackLocale||e.locale),this._currentRoute=a.shallowRef("index"),this._revision=a.shallowRef(0),e.messages)for(const[o,u]of Object.entries(e.messages))this.helper.loadTranslations(o,u)}get locale(){return this._locale}set locale(e){typeof e=="string"?this._locale.value=e:this._locale=e}get fallbackLocale(){return this._fallbackLocale}set fallbackLocale(e){typeof e=="string"?this._fallbackLocale.value=e:this._fallbackLocale=e}get currentRoute(){return this._currentRoute}setRoute(e){this._currentRoute.value=e}getLocale(){return this._locale.value}getFallbackLocale(){return this._fallbackLocale.value}getRoute(){return this._currentRoute.value}addTranslations(e,r,o=!0){super.loadTranslationsCore(e,r,o),this._revision.value++,this.notifyListeners()}addRouteTranslations(e,r,o,u=!0){super.loadRouteTranslationsCore(e,r,o,u),this._revision.value++,this.notifyListeners()}mergeTranslations(e,r,o){this.helper.mergeTranslation(e,r,o,!0),this._revision.value++,this.notifyListeners()}clearCache(){super.clearCache(),this._revision.value++,this.notifyListeners()}subscribeToChanges(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notifyListeners(){this.listeners.forEach(e=>e())}getAllTranslations(){const e={};for(const[r,o]of this.storage.translations)if(!r.includes(":"))e[r]=o;else{const u=r.split(":")[0];u&&(e[u]||(e[u]={}),Object.assign(e[u],o))}return e}getStorage(){return this.storage}getRouteCache(){const e={};for(const[r,o]of this.storage.translations)e[r]=o;return e}}function te(t){const{routingStrategy:e,locales:r,defaultLocale:o,...u}=t,l=new X(u);let d=null,h=e||null;return{global:l,setRoutingStrategy:n=>{h=n,d&&d.provide(A,n)},install(n){d=n,n.provide(T,l),h&&n.provide(A,h),r&&n.provide(V,r),o&&n.provide(F,o),n.config.globalProperties.$t=(c,g,m,b)=>l.t(c,g,m,b),n.config.globalProperties.$ts=(c,g,m,b)=>l.ts(c,g,m,b),n.config.globalProperties.$tc=(c,g,m)=>l.tc(c,g,m),n.config.globalProperties.$tn=(c,g)=>l.tn(c,g),n.config.globalProperties.$td=(c,g)=>l.td(c,g),n.config.globalProperties.$tdr=(c,g)=>l.tdr(c,g),n.config.globalProperties.$has=(c,g)=>l.has(c,g),n.config.globalProperties.$i18n=l,n.component("I18nT",J),n.component("I18nLink",G),n.component("I18nGroup",z),n.component("I18nSwitcher",Z)}}}function ne(t,e,r){const o=e.map(l=>l.code),u=(l,d)=>{const i=(typeof l=="string"?l:l.path||"/").split("/").filter(Boolean),n=i[0];n!==void 0&&o.includes(n)&&i.shift();const c=`/${i.join("/")}`;return d===r?c:`/${d}${c==="/"?"":c}`};return{linkComponent:Y.RouterLink,getCurrentPath:()=>t.currentRoute.value.path,push:l=>{t.push(l.path).catch(()=>{})},replace:l=>{t.replace(l.path).catch(()=>{})},resolvePath:(l,d)=>u(l,d),getRoute:()=>({fullPath:t.currentRoute.value.fullPath,query:t.currentRoute.value.query})}}Object.defineProperty(exports,"FormatService",{enumerable:!0,get:()=>U.FormatService});Object.defineProperty(exports,"defaultPlural",{enumerable:!0,get:()=>U.defaultPlural});Object.defineProperty(exports,"interpolate",{enumerable:!0,get:()=>U.interpolate});exports.I18nDefaultLocaleKey=F;exports.I18nGroup=z;exports.I18nInjectionKey=T;exports.I18nLink=G;exports.I18nLocalesKey=V;exports.I18nSwitcher=Z;exports.I18nT=J;exports.VueI18n=X;exports.createI18n=te;exports.createVueRouterAdapter=ne;exports.useI18n=Q;exports.useLocaleHead=ee;
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { BaseI18n as
|
|
3
|
-
import { FormatService as
|
|
4
|
-
import { RouterLink as
|
|
5
|
-
const
|
|
1
|
+
import { defineComponent as B, inject as k, h as y, computed as C, ref as q, onMounted as Q, onUnmounted as X, nextTick as Y, shallowRef as K } from "vue";
|
|
2
|
+
import { BaseI18n as ee } from "@i18n-micro/core";
|
|
3
|
+
import { FormatService as me, defaultPlural as ve, interpolate as be } from "@i18n-micro/core";
|
|
4
|
+
import { RouterLink as te } from "vue-router";
|
|
5
|
+
const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-locales"), Z = /* @__PURE__ */ Symbol("i18n-default-locale"), A = /* @__PURE__ */ Symbol("i18n-router-strategy"), ne = B({
|
|
6
6
|
name: "I18nGroup",
|
|
7
7
|
props: {
|
|
8
8
|
prefix: {
|
|
@@ -15,11 +15,11 @@ const D = /* @__PURE__ */ Symbol("i18n"), V = /* @__PURE__ */ Symbol("i18n-local
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
setup(t, { slots: e }) {
|
|
18
|
-
const a =
|
|
18
|
+
const a = k(E);
|
|
19
19
|
if (!a)
|
|
20
20
|
throw new Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");
|
|
21
21
|
const r = (c, o) => a.t(`${t.prefix}.${c}`, o, void 0, a.getRoute());
|
|
22
|
-
return () =>
|
|
22
|
+
return () => y(
|
|
23
23
|
"div",
|
|
24
24
|
{
|
|
25
25
|
class: ["i18n-group", t.groupClass]
|
|
@@ -27,7 +27,7 @@ const D = /* @__PURE__ */ Symbol("i18n"), V = /* @__PURE__ */ Symbol("i18n-local
|
|
|
27
27
|
e.default?.({ prefix: t.prefix, t: r })
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
|
-
}),
|
|
30
|
+
}), ae = B({
|
|
31
31
|
name: "I18nLink",
|
|
32
32
|
props: {
|
|
33
33
|
to: {
|
|
@@ -44,10 +44,10 @@ const D = /* @__PURE__ */ Symbol("i18n"), V = /* @__PURE__ */ Symbol("i18n-local
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
setup(t, { slots: e }) {
|
|
47
|
-
const a =
|
|
47
|
+
const a = k(E), r = k(A, void 0);
|
|
48
48
|
if (!a)
|
|
49
49
|
throw new Error("[i18n-micro] I18nLink: i18n instance not found. Make sure i18n plugin is installed.");
|
|
50
|
-
const c =
|
|
50
|
+
const c = C(() => typeof t.to == "string" ? /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to) : !1), o = C(() => {
|
|
51
51
|
if (c.value)
|
|
52
52
|
return t.to;
|
|
53
53
|
if (t.localeRoute) {
|
|
@@ -58,33 +58,33 @@ const D = /* @__PURE__ */ Symbol("i18n"), V = /* @__PURE__ */ Symbol("i18n-local
|
|
|
58
58
|
return typeof t.to == "string" ? t.to : t.to.path || "/";
|
|
59
59
|
const l = r.resolvePath(t.to, a.locale.value);
|
|
60
60
|
return typeof l == "string" ? l : l.path || "/";
|
|
61
|
-
}), u =
|
|
61
|
+
}), u = C(() => {
|
|
62
62
|
if (c.value || !r)
|
|
63
63
|
return !1;
|
|
64
64
|
const l = r.getCurrentPath().replace(/\/$/, ""), n = o.value.replace(/\/$/, "");
|
|
65
65
|
return l === n;
|
|
66
|
-
}),
|
|
67
|
-
return () => c.value ?
|
|
66
|
+
}), d = C(() => u.value ? t.activeStyle : {});
|
|
67
|
+
return () => c.value ? y(
|
|
68
68
|
"a",
|
|
69
69
|
{
|
|
70
70
|
href: o.value,
|
|
71
71
|
target: "_blank",
|
|
72
72
|
rel: "noopener noreferrer",
|
|
73
|
-
style:
|
|
73
|
+
style: d.value
|
|
74
74
|
},
|
|
75
75
|
e.default?.()
|
|
76
|
-
) : r?.linkComponent ?
|
|
76
|
+
) : r?.linkComponent ? y(
|
|
77
77
|
r.linkComponent,
|
|
78
78
|
{
|
|
79
79
|
to: o.value,
|
|
80
|
-
style:
|
|
80
|
+
style: d.value
|
|
81
81
|
},
|
|
82
82
|
{ default: e.default }
|
|
83
|
-
) :
|
|
83
|
+
) : y(
|
|
84
84
|
"a",
|
|
85
85
|
{
|
|
86
86
|
href: o.value,
|
|
87
|
-
style:
|
|
87
|
+
style: d.value,
|
|
88
88
|
onClick: (l) => {
|
|
89
89
|
l.preventDefault(), r ? r.push({ path: o.value }) : window.location.href = o.value;
|
|
90
90
|
}
|
|
@@ -92,7 +92,7 @@ const D = /* @__PURE__ */ Symbol("i18n"), V = /* @__PURE__ */ Symbol("i18n-local
|
|
|
92
92
|
e.default?.()
|
|
93
93
|
);
|
|
94
94
|
}
|
|
95
|
-
}),
|
|
95
|
+
}), re = B({
|
|
96
96
|
name: "I18nSwitcher",
|
|
97
97
|
props: {
|
|
98
98
|
customLabels: {
|
|
@@ -153,38 +153,38 @@ const D = /* @__PURE__ */ Symbol("i18n"), V = /* @__PURE__ */ Symbol("i18n-local
|
|
|
153
153
|
}
|
|
154
154
|
},
|
|
155
155
|
setup(t, { slots: e }) {
|
|
156
|
-
const a =
|
|
156
|
+
const a = k(E), r = k(A, void 0), c = k(G, void 0);
|
|
157
157
|
if (!a)
|
|
158
158
|
throw new Error("[i18n-micro] I18nSwitcher: i18n instance not found. Make sure i18n plugin is installed.");
|
|
159
159
|
if (!c && !t.locales)
|
|
160
160
|
throw new Error(
|
|
161
161
|
"[i18n-micro] I18nSwitcher: locales not provided. Make sure app.provide(I18nLocalesKey, locales) is called or pass locales prop."
|
|
162
162
|
);
|
|
163
|
-
const o =
|
|
163
|
+
const o = C(() => t.locales || c || []), u = C(() => t.currentLocale !== void 0 ? typeof t.currentLocale == "function" ? t.currentLocale() : t.currentLocale : a.locale.value), d = C(() => t.getLocaleName ? t.getLocaleName() || null : o.value.find((p) => p.code === a.locale.value)?.displayName || null), l = q(!1), n = q(null), i = (s) => {
|
|
164
164
|
s && (s.stopPropagation(), s.preventDefault()), l.value = !l.value;
|
|
165
|
-
},
|
|
166
|
-
const s = o.value.find((
|
|
167
|
-
return s ?
|
|
168
|
-
}),
|
|
169
|
-
if (l.value = !1, await
|
|
165
|
+
}, h = (s) => t.customLabels[s.code] || s.displayName || s.code, m = C(() => {
|
|
166
|
+
const s = o.value.find((p) => p.code === u.value);
|
|
167
|
+
return s ? h(s) : d.value || u.value;
|
|
168
|
+
}), b = async (s) => {
|
|
169
|
+
if (l.value = !1, await Y(), t.switchLocale) {
|
|
170
170
|
t.switchLocale(s);
|
|
171
171
|
return;
|
|
172
172
|
}
|
|
173
173
|
if (a.locale.value = s, !r)
|
|
174
174
|
return;
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
return typeof
|
|
175
|
+
const p = r.getCurrentPath(), v = t.localeRoute ? (() => {
|
|
176
|
+
const g = t.localeRoute(p, s);
|
|
177
|
+
return typeof g == "string" ? g : g.path || "/";
|
|
178
178
|
})() : r?.resolvePath ? (() => {
|
|
179
|
-
const
|
|
180
|
-
return typeof
|
|
181
|
-
})() :
|
|
182
|
-
r.push({ path:
|
|
183
|
-
},
|
|
179
|
+
const g = r.resolvePath(p, s);
|
|
180
|
+
return typeof g == "string" ? g : g.path || "/";
|
|
181
|
+
})() : p;
|
|
182
|
+
r.push({ path: v });
|
|
183
|
+
}, S = {
|
|
184
184
|
position: "relative",
|
|
185
185
|
display: "inline-block",
|
|
186
186
|
verticalAlign: "middle"
|
|
187
|
-
},
|
|
187
|
+
}, R = {
|
|
188
188
|
padding: "4px 12px",
|
|
189
189
|
fontSize: "16px",
|
|
190
190
|
cursor: "pointer",
|
|
@@ -194,7 +194,7 @@ const D = /* @__PURE__ */ Symbol("i18n"), V = /* @__PURE__ */ Symbol("i18n-local
|
|
|
194
194
|
display: "flex",
|
|
195
195
|
alignItems: "center",
|
|
196
196
|
justifyContent: "space-between"
|
|
197
|
-
},
|
|
197
|
+
}, T = {
|
|
198
198
|
position: "absolute",
|
|
199
199
|
top: "100%",
|
|
200
200
|
left: "0",
|
|
@@ -206,126 +206,126 @@ const D = /* @__PURE__ */ Symbol("i18n"), V = /* @__PURE__ */ Symbol("i18n-local
|
|
|
206
206
|
margin: "4px 0 0 0",
|
|
207
207
|
minWidth: "150px",
|
|
208
208
|
boxShadow: "0 2px 8px rgba(0,0,0,0.15)"
|
|
209
|
-
},
|
|
209
|
+
}, O = {
|
|
210
210
|
margin: "0",
|
|
211
211
|
padding: "0"
|
|
212
|
-
},
|
|
212
|
+
}, j = {
|
|
213
213
|
display: "block",
|
|
214
214
|
padding: "8px 12px",
|
|
215
215
|
color: "#333",
|
|
216
216
|
textDecoration: "none",
|
|
217
217
|
transition: "background-color 0.3s ease",
|
|
218
218
|
cursor: "pointer"
|
|
219
|
-
},
|
|
219
|
+
}, $ = {
|
|
220
220
|
fontWeight: "bold",
|
|
221
221
|
color: "#007bff"
|
|
222
|
-
},
|
|
222
|
+
}, z = {
|
|
223
223
|
marginLeft: "8px",
|
|
224
224
|
display: "inline-block",
|
|
225
225
|
transition: "transform 0.3s ease"
|
|
226
|
-
},
|
|
226
|
+
}, V = {
|
|
227
227
|
transform: "rotate(180deg)"
|
|
228
|
-
},
|
|
228
|
+
}, L = (s) => s ? Array.isArray(s) ? s : [s] : [], x = (s) => {
|
|
229
229
|
if (!l.value) return;
|
|
230
|
-
const
|
|
231
|
-
if (!
|
|
232
|
-
const
|
|
233
|
-
!
|
|
230
|
+
const p = s.target;
|
|
231
|
+
if (!p || !n.value) return;
|
|
232
|
+
const v = n.value.contains(p), g = p.closest(".i18n-switcher-button") !== null;
|
|
233
|
+
!v && !g && (l.value = !1);
|
|
234
234
|
};
|
|
235
|
-
return
|
|
236
|
-
document.addEventListener("click",
|
|
237
|
-
}),
|
|
238
|
-
document.removeEventListener("click",
|
|
235
|
+
return Q(() => {
|
|
236
|
+
document.addEventListener("click", x);
|
|
237
|
+
}), X(() => {
|
|
238
|
+
document.removeEventListener("click", x);
|
|
239
239
|
}), () => {
|
|
240
240
|
const s = [];
|
|
241
|
-
e["before-button"] && s.push(...
|
|
242
|
-
const
|
|
243
|
-
if (e["before-selected-locale"] &&
|
|
244
|
-
|
|
241
|
+
e["before-button"] && s.push(...L(e["before-button"]()));
|
|
242
|
+
const p = [];
|
|
243
|
+
if (e["before-selected-locale"] && p.push(...L(e["before-selected-locale"]())), p.push(y("span", m.value)), e["after-selected-locale"] && p.push(...L(e["after-selected-locale"]())), p.push(
|
|
244
|
+
y(
|
|
245
245
|
"span",
|
|
246
246
|
{
|
|
247
247
|
style: {
|
|
248
|
-
...
|
|
249
|
-
...l.value ?
|
|
248
|
+
...z,
|
|
249
|
+
...l.value ? V : {},
|
|
250
250
|
...t.customIconStyle
|
|
251
251
|
}
|
|
252
252
|
},
|
|
253
253
|
"▼"
|
|
254
254
|
)
|
|
255
255
|
), s.push(
|
|
256
|
-
|
|
256
|
+
y(
|
|
257
257
|
"button",
|
|
258
258
|
{
|
|
259
259
|
class: "i18n-switcher-button",
|
|
260
|
-
style: { ...
|
|
261
|
-
onClick: (
|
|
262
|
-
|
|
260
|
+
style: { ...R, ...t.customButtonStyle },
|
|
261
|
+
onClick: (v) => {
|
|
262
|
+
v.preventDefault(), v.stopPropagation(), i(v);
|
|
263
263
|
},
|
|
264
264
|
type: "button",
|
|
265
265
|
ariaHaspopup: !0,
|
|
266
266
|
ariaExpanded: l.value
|
|
267
267
|
},
|
|
268
|
-
|
|
268
|
+
p
|
|
269
269
|
)
|
|
270
|
-
), e["before-dropdown"] && s.push(...
|
|
271
|
-
const
|
|
272
|
-
e["before-dropdown-items"] &&
|
|
273
|
-
const
|
|
274
|
-
e["before-item"] &&
|
|
275
|
-
const
|
|
276
|
-
e["before-link-content"] &&
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
270
|
+
), e["before-dropdown"] && s.push(...L(e["before-dropdown"]())), l.value) {
|
|
271
|
+
const v = [];
|
|
272
|
+
e["before-dropdown-items"] && v.push(...L(e["before-dropdown-items"]())), o.value.forEach((g) => {
|
|
273
|
+
const M = [];
|
|
274
|
+
e["before-item"] && M.push(...L(e["before-item"]({ locale: g })));
|
|
275
|
+
const _ = [];
|
|
276
|
+
e["before-link-content"] && _.push(...L(e["before-link-content"]({ locale: g }))), _.push(h(g)), e["after-link-content"] && _.push(...L(e["after-link-content"]({ locale: g })));
|
|
277
|
+
const N = typeof window < "u" ? window.location.pathname : "/", W = t.localeRoute ? t.localeRoute(N, g.code) : r?.resolvePath ? r.resolvePath(N, g.code) : N, D = typeof W == "string" ? W : W.path || "#", U = g.code === u.value;
|
|
278
|
+
M.push(
|
|
279
|
+
y(
|
|
280
280
|
"a",
|
|
281
281
|
{
|
|
282
|
-
class: `switcher-locale-${
|
|
283
|
-
href: typeof
|
|
282
|
+
class: `switcher-locale-${g.code}`,
|
|
283
|
+
href: typeof D == "string" ? D : "#",
|
|
284
284
|
style: {
|
|
285
|
-
...
|
|
286
|
-
...
|
|
285
|
+
...j,
|
|
286
|
+
...U ? $ : {},
|
|
287
287
|
...t.customLinkStyle
|
|
288
288
|
},
|
|
289
289
|
// Prevent default navigation, use only handleSwitchLocale
|
|
290
|
-
onClick: (
|
|
291
|
-
|
|
290
|
+
onClick: (F) => {
|
|
291
|
+
F.preventDefault(), F.stopPropagation(), b(g.code);
|
|
292
292
|
}
|
|
293
293
|
},
|
|
294
|
-
|
|
294
|
+
_
|
|
295
295
|
)
|
|
296
|
-
), e["after-item"] &&
|
|
297
|
-
|
|
296
|
+
), e["after-item"] && M.push(...L(e["after-item"]({ locale: g }))), v.push(
|
|
297
|
+
y(
|
|
298
298
|
"li",
|
|
299
299
|
{
|
|
300
|
-
key:
|
|
301
|
-
style: { ...
|
|
300
|
+
key: g.code,
|
|
301
|
+
style: { ...O, ...t.customItemStyle }
|
|
302
302
|
},
|
|
303
|
-
|
|
303
|
+
M
|
|
304
304
|
)
|
|
305
305
|
);
|
|
306
|
-
}), e["after-dropdown-items"] &&
|
|
307
|
-
|
|
306
|
+
}), e["after-dropdown-items"] && v.push(...L(e["after-dropdown-items"]())), s.push(
|
|
307
|
+
y(
|
|
308
308
|
"ul",
|
|
309
309
|
{
|
|
310
310
|
class: "i18n-switcher-dropdown",
|
|
311
|
-
style: { ...
|
|
311
|
+
style: { ...T, ...t.customDropdownStyle }
|
|
312
312
|
},
|
|
313
|
-
|
|
313
|
+
v
|
|
314
314
|
)
|
|
315
315
|
);
|
|
316
316
|
}
|
|
317
|
-
return e["after-dropdown"] && s.push(...
|
|
317
|
+
return e["after-dropdown"] && s.push(...L(e["after-dropdown"]())), y(
|
|
318
318
|
"div",
|
|
319
319
|
{
|
|
320
320
|
ref: n,
|
|
321
321
|
class: "i18n-switcher-wrapper",
|
|
322
|
-
style: { ...
|
|
322
|
+
style: { ...S, ...t.customWrapperStyle }
|
|
323
323
|
},
|
|
324
324
|
s
|
|
325
325
|
);
|
|
326
326
|
};
|
|
327
327
|
}
|
|
328
|
-
}),
|
|
328
|
+
}), oe = B({
|
|
329
329
|
name: "I18nT",
|
|
330
330
|
props: {
|
|
331
331
|
keypath: {
|
|
@@ -370,22 +370,22 @@ const D = /* @__PURE__ */ Symbol("i18n"), V = /* @__PURE__ */ Symbol("i18n-local
|
|
|
370
370
|
}
|
|
371
371
|
},
|
|
372
372
|
setup(t, { slots: e, attrs: a }) {
|
|
373
|
-
const r =
|
|
373
|
+
const r = k(E);
|
|
374
374
|
if (!r)
|
|
375
375
|
throw new Error("[i18n-micro] I18nT: i18n instance not found. Make sure i18n plugin is installed.");
|
|
376
376
|
return () => {
|
|
377
377
|
const c = {}, o = r.getRoute();
|
|
378
378
|
if (t.number !== void 0) {
|
|
379
|
-
const n = Number(t.number), i = r.tn(n),
|
|
380
|
-
return
|
|
379
|
+
const n = Number(t.number), i = r.tn(n), h = r.t(t.keypath, { number: i, ...t.params }, void 0, o);
|
|
380
|
+
return y(t.tag, { ...a, innerHTML: h });
|
|
381
381
|
}
|
|
382
382
|
if (t.date !== void 0) {
|
|
383
383
|
const n = r.td(t.date), i = r.t(t.keypath, { date: n, ...t.params }, void 0, o);
|
|
384
|
-
return
|
|
384
|
+
return y(t.tag, { ...a, innerHTML: i });
|
|
385
385
|
}
|
|
386
386
|
if (t.relativeDate !== void 0) {
|
|
387
387
|
const n = r.tdr(t.relativeDate), i = r.t(t.keypath, { relativeDate: n, ...t.params }, void 0, o);
|
|
388
|
-
return
|
|
388
|
+
return y(t.tag, { ...a, innerHTML: i });
|
|
389
389
|
}
|
|
390
390
|
if (t.plural !== void 0) {
|
|
391
391
|
const n = Number.parseInt(t.plural.toString(), 10);
|
|
@@ -395,46 +395,46 @@ const D = /* @__PURE__ */ Symbol("i18n"), V = /* @__PURE__ */ Symbol("i18n-local
|
|
|
395
395
|
n,
|
|
396
396
|
t.params,
|
|
397
397
|
r.locale.value,
|
|
398
|
-
(
|
|
398
|
+
(h, m, b) => r.t(h, m, b, o)
|
|
399
399
|
);
|
|
400
|
-
return
|
|
400
|
+
return y(t.tag, { ...a, innerHTML: i || "" });
|
|
401
401
|
} else {
|
|
402
402
|
const i = r.tc(t.keypath, { count: n, ...t.params });
|
|
403
|
-
return
|
|
403
|
+
return y(t.tag, { ...a, innerHTML: i });
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
const u = (r.t(t.keypath, { ...t.params, ...c }, void 0, o) ?? "").toString();
|
|
407
407
|
if (t.hideIfEmpty && !u.trim())
|
|
408
408
|
return t.defaultValue ?? null;
|
|
409
409
|
if (t.html)
|
|
410
|
-
return
|
|
410
|
+
return y(t.tag, { ...a, innerHTML: u });
|
|
411
411
|
if (e.default)
|
|
412
|
-
return
|
|
413
|
-
const
|
|
412
|
+
return y(t.tag, a, e.default({ translation: u }));
|
|
413
|
+
const d = [];
|
|
414
414
|
let l = 0;
|
|
415
415
|
for (const [n, i] of Object.entries(e)) {
|
|
416
416
|
if (n === "default") continue;
|
|
417
|
-
const
|
|
418
|
-
|
|
417
|
+
const h = `{${n}}`, m = u.indexOf(h, l);
|
|
418
|
+
m !== -1 && (m > l && d.push(u.slice(l, m)), i && d.push(y(i)), l = m + h.length);
|
|
419
419
|
}
|
|
420
|
-
return l < u.length &&
|
|
420
|
+
return l < u.length && d.push(u.slice(l)), e.default ? y(t.tag, a, e.default({ children: d })) : d.length > 0 ? y(t.tag, a, d) : y(t.tag, a, u);
|
|
421
421
|
};
|
|
422
422
|
}
|
|
423
423
|
});
|
|
424
|
-
function
|
|
425
|
-
const e =
|
|
424
|
+
function le(t) {
|
|
425
|
+
const e = k(E), a = k(A, void 0), r = k(G, void 0), c = k(Z, void 0);
|
|
426
426
|
if (!e)
|
|
427
427
|
throw new Error("[i18n-micro] useI18n() must be called after app.use(i18n). Make sure i18n plugin is installed.");
|
|
428
428
|
if (!r)
|
|
429
429
|
throw new Error("[i18n-micro] I18nLocalesKey not provided. Make sure app.provide(I18nLocalesKey, locales) is called.");
|
|
430
430
|
if (!c)
|
|
431
431
|
throw new Error("[i18n-micro] I18nDefaultLocaleKey not provided. Make sure app.provide(I18nDefaultLocaleKey, defaultLocale) is called.");
|
|
432
|
-
const o = t?.locales || r, u = t?.defaultLocale || c,
|
|
432
|
+
const o = t?.locales || r, u = t?.defaultLocale || c, d = (l, n) => a?.resolvePath ? a.resolvePath(l, n || e.locale.value) : l;
|
|
433
433
|
return {
|
|
434
434
|
// Direct access to instance
|
|
435
435
|
instance: e,
|
|
436
436
|
// Locale (reactive)
|
|
437
|
-
locale:
|
|
437
|
+
locale: C({
|
|
438
438
|
get: () => e.locale.value,
|
|
439
439
|
set: (l) => {
|
|
440
440
|
e.locale.value = l;
|
|
@@ -445,14 +445,14 @@ function ne(t) {
|
|
|
445
445
|
defaultLocale: () => u,
|
|
446
446
|
getLocaleName: () => o.find((n) => n.code === e.locale.value)?.displayName || null,
|
|
447
447
|
// Routing helpers
|
|
448
|
-
localeRoute:
|
|
448
|
+
localeRoute: d,
|
|
449
449
|
localePath: (l, n) => {
|
|
450
|
-
const i =
|
|
450
|
+
const i = d(l, n);
|
|
451
451
|
return typeof i == "string" ? i : i.path || "/";
|
|
452
452
|
},
|
|
453
453
|
switchLocale: (l) => {
|
|
454
454
|
if (e.locale.value = l, a) {
|
|
455
|
-
const n = a.getCurrentPath(), i =
|
|
455
|
+
const n = a.getCurrentPath(), i = d(n, l);
|
|
456
456
|
a.push(typeof i == "string" ? { path: i } : { path: i.path || "/" });
|
|
457
457
|
}
|
|
458
458
|
},
|
|
@@ -475,90 +475,112 @@ function ne(t) {
|
|
|
475
475
|
clearCache: e.clearCache.bind(e)
|
|
476
476
|
};
|
|
477
477
|
}
|
|
478
|
-
function
|
|
479
|
-
const { addDirAttribute: e = !0, identifierAttribute: a = "id", addSeoAttributes: r = !0, baseUrl: c = "/" } = t, { getLocale: o, getLocales: u, localeRoute:
|
|
478
|
+
function de(t = {}) {
|
|
479
|
+
const { addDirAttribute: e = !0, identifierAttribute: a = "id", addSeoAttributes: r = !0, baseUrl: c = "/" } = t, { getLocale: o, getLocales: u, localeRoute: d } = le(), l = k(A, void 0), n = q({
|
|
480
480
|
htmlAttrs: {},
|
|
481
481
|
link: [],
|
|
482
482
|
meta: []
|
|
483
483
|
});
|
|
484
|
-
function i(
|
|
485
|
-
const
|
|
486
|
-
for (const
|
|
487
|
-
|
|
488
|
-
const
|
|
489
|
-
return
|
|
484
|
+
function i(m, b) {
|
|
485
|
+
const S = new URL(m, "http://localhost"), R = new URLSearchParams(S.search), T = {};
|
|
486
|
+
for (const j of b)
|
|
487
|
+
R.has(j) && (T[j] = R.get(j));
|
|
488
|
+
const O = new URLSearchParams(T);
|
|
489
|
+
return O.toString() ? `${S.pathname}?${O.toString()}` : S.pathname;
|
|
490
490
|
}
|
|
491
|
-
function
|
|
491
|
+
function h(m = []) {
|
|
492
492
|
if (!l) {
|
|
493
493
|
n.value = { htmlAttrs: {}, link: [], meta: [] };
|
|
494
494
|
return;
|
|
495
495
|
}
|
|
496
|
-
const
|
|
497
|
-
if (!
|
|
496
|
+
const b = o(), S = u(), R = S.find((f) => f.code === b);
|
|
497
|
+
if (!R)
|
|
498
498
|
return;
|
|
499
|
-
const
|
|
500
|
-
let
|
|
501
|
-
|
|
502
|
-
const
|
|
503
|
-
let
|
|
504
|
-
|
|
505
|
-
|
|
499
|
+
const T = R.iso || b, O = R.og || T, j = R.dir || "auto";
|
|
500
|
+
let $ = l.getCurrentPath();
|
|
501
|
+
$.startsWith("/") || ($ = `/${$}`);
|
|
502
|
+
const z = $.split("/").filter(Boolean), V = S.find((f) => z[0] === f.code);
|
|
503
|
+
let L = $, x, s;
|
|
504
|
+
const p = typeof c == "function" ? c() : c;
|
|
505
|
+
if (V) {
|
|
506
|
+
L = $.slice(V.code.length + 1) || "/", x = i(L, m);
|
|
507
|
+
const f = `/${b}`;
|
|
508
|
+
s = `${p}${f}${x.startsWith("/") ? "" : "/"}${x}`;
|
|
509
|
+
} else
|
|
510
|
+
x = i($, m), s = `${p}${x.startsWith("/") ? "" : "/"}${x}`;
|
|
506
511
|
if (n.value = {
|
|
507
512
|
htmlAttrs: {
|
|
508
|
-
lang:
|
|
509
|
-
...e ? { dir:
|
|
513
|
+
lang: T,
|
|
514
|
+
...e ? { dir: j } : {}
|
|
510
515
|
},
|
|
511
516
|
link: [],
|
|
512
517
|
meta: []
|
|
513
518
|
}, !r)
|
|
514
519
|
return;
|
|
515
|
-
const
|
|
520
|
+
const v = S.filter((f) => !f.disabled && f.seo !== !1), g = {
|
|
516
521
|
[a]: "i18n-og",
|
|
517
522
|
property: "og:locale",
|
|
518
|
-
content:
|
|
519
|
-
},
|
|
523
|
+
content: O
|
|
524
|
+
}, M = {
|
|
520
525
|
[a]: "i18n-og-url",
|
|
521
526
|
property: "og:url",
|
|
522
527
|
content: s
|
|
523
|
-
},
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
+
}, _ = v.filter((f) => f.code !== b).map((f) => {
|
|
529
|
+
const I = f.og || f.iso || f.code;
|
|
530
|
+
return {
|
|
531
|
+
[a]: `i18n-og-alt-${I}`,
|
|
532
|
+
property: "og:locale:alternate",
|
|
533
|
+
content: I
|
|
534
|
+
};
|
|
535
|
+
}), N = {
|
|
528
536
|
[a]: "i18n-can",
|
|
529
537
|
rel: "canonical",
|
|
530
538
|
href: s
|
|
531
|
-
},
|
|
532
|
-
if (!
|
|
539
|
+
}, W = v.flatMap((f) => {
|
|
540
|
+
if (!d || !l)
|
|
533
541
|
return [];
|
|
534
|
-
const
|
|
542
|
+
const I = l.getCurrentPath(), w = d(I, f.code), P = typeof w == "string" ? w : w?.path || "/";
|
|
535
543
|
if (!P)
|
|
536
544
|
return [];
|
|
537
|
-
let
|
|
538
|
-
P.startsWith("http://") || P.startsWith("https://") ?
|
|
539
|
-
const
|
|
545
|
+
let H;
|
|
546
|
+
P.startsWith("http://") || P.startsWith("https://") ? H = P : H = `${typeof c == "function" ? c() : c}${P.startsWith("/") ? "" : "/"}${P}`;
|
|
547
|
+
const J = [
|
|
540
548
|
{
|
|
541
|
-
[a]: `i18n-alternate-${
|
|
549
|
+
[a]: `i18n-alternate-${f.code}`,
|
|
542
550
|
rel: "alternate",
|
|
543
|
-
href:
|
|
544
|
-
hreflang:
|
|
551
|
+
href: H,
|
|
552
|
+
hreflang: f.code
|
|
545
553
|
}
|
|
546
554
|
];
|
|
547
|
-
return
|
|
548
|
-
[a]: `i18n-alternate-${
|
|
555
|
+
return f.iso && f.iso !== f.code && J.push({
|
|
556
|
+
[a]: `i18n-alternate-${f.iso}`,
|
|
549
557
|
rel: "alternate",
|
|
550
|
-
href:
|
|
551
|
-
hreflang:
|
|
552
|
-
}),
|
|
553
|
-
});
|
|
554
|
-
|
|
558
|
+
href: H,
|
|
559
|
+
hreflang: f.iso
|
|
560
|
+
}), J;
|
|
561
|
+
}), D = k(Z, void 0);
|
|
562
|
+
let U = null;
|
|
563
|
+
const F = D ? S.find((f) => f.code === D) : void 0;
|
|
564
|
+
if (d && l && D && F?.seo !== !1) {
|
|
565
|
+
const f = l.getCurrentPath(), I = d(f, D), w = typeof I == "string" ? I : I?.path || "/";
|
|
566
|
+
if (w) {
|
|
567
|
+
let P;
|
|
568
|
+
w.startsWith("http://") || w.startsWith("https://") ? P = w : P = `${typeof c == "function" ? c() : c}${w.startsWith("/") ? "" : "/"}${w}`, U = {
|
|
569
|
+
[a]: "i18n-xd",
|
|
570
|
+
rel: "alternate",
|
|
571
|
+
href: P,
|
|
572
|
+
hreflang: "x-default"
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
n.value.meta = [g, M, ..._], n.value.link = [N, ...W, ...U ? [U] : []];
|
|
555
577
|
}
|
|
556
578
|
return {
|
|
557
579
|
metaObject: n,
|
|
558
|
-
updateMeta:
|
|
580
|
+
updateMeta: h
|
|
559
581
|
};
|
|
560
582
|
}
|
|
561
|
-
class
|
|
583
|
+
class ie extends ee {
|
|
562
584
|
constructor(e) {
|
|
563
585
|
const a = {
|
|
564
586
|
translations: /* @__PURE__ */ new Map()
|
|
@@ -568,7 +590,7 @@ class ae extends J {
|
|
|
568
590
|
plural: e.plural,
|
|
569
591
|
missingWarn: e.missingWarn,
|
|
570
592
|
missingHandler: e.missingHandler
|
|
571
|
-
}), this.listeners = /* @__PURE__ */ new Set(), this.storage = a, this._locale =
|
|
593
|
+
}), this.listeners = /* @__PURE__ */ new Set(), this.storage = a, this._locale = K(e.locale), this._fallbackLocale = K(e.fallbackLocale || e.locale), this._currentRoute = K("index"), this._revision = K(0), e.messages)
|
|
572
594
|
for (const [r, c] of Object.entries(e.messages))
|
|
573
595
|
this.helper.loadTranslations(r, c);
|
|
574
596
|
}
|
|
@@ -638,22 +660,22 @@ class ae extends J {
|
|
|
638
660
|
return e;
|
|
639
661
|
}
|
|
640
662
|
}
|
|
641
|
-
function
|
|
642
|
-
const { routingStrategy: e, locales: a, defaultLocale: r, ...c } = t, o = new
|
|
643
|
-
let u = null,
|
|
663
|
+
function he(t) {
|
|
664
|
+
const { routingStrategy: e, locales: a, defaultLocale: r, ...c } = t, o = new ie(c);
|
|
665
|
+
let u = null, d = e || null;
|
|
644
666
|
return {
|
|
645
667
|
global: o,
|
|
646
668
|
// Access to instance outside components
|
|
647
669
|
setRoutingStrategy: (n) => {
|
|
648
|
-
|
|
670
|
+
d = n, u && u.provide(A, n);
|
|
649
671
|
},
|
|
650
672
|
// Method for setting adapter after creation
|
|
651
673
|
install(n) {
|
|
652
|
-
u = n, n.provide(
|
|
674
|
+
u = n, n.provide(E, o), d && n.provide(A, d), a && n.provide(G, a), r && n.provide(Z, r), n.config.globalProperties.$t = (i, h, m, b) => o.t(i, h, m, b), n.config.globalProperties.$ts = (i, h, m, b) => o.ts(i, h, m, b), n.config.globalProperties.$tc = (i, h, m) => o.tc(i, h, m), n.config.globalProperties.$tn = (i, h) => o.tn(i, h), n.config.globalProperties.$td = (i, h) => o.td(i, h), n.config.globalProperties.$tdr = (i, h) => o.tdr(i, h), n.config.globalProperties.$has = (i, h) => o.has(i, h), n.config.globalProperties.$i18n = o, n.component("I18nT", oe), n.component("I18nLink", ae), n.component("I18nGroup", ne), n.component("I18nSwitcher", re);
|
|
653
675
|
}
|
|
654
676
|
};
|
|
655
677
|
}
|
|
656
|
-
function
|
|
678
|
+
function ge(t, e, a) {
|
|
657
679
|
const r = e.map((o) => o.code), c = (o, u) => {
|
|
658
680
|
const l = (typeof o == "string" ? o : o.path || "/").split("/").filter(Boolean), n = l[0];
|
|
659
681
|
n !== void 0 && r.includes(n) && l.shift();
|
|
@@ -661,7 +683,7 @@ function ue(t, e, a) {
|
|
|
661
683
|
return u === a ? i : `/${u}${i === "/" ? "" : i}`;
|
|
662
684
|
};
|
|
663
685
|
return {
|
|
664
|
-
linkComponent:
|
|
686
|
+
linkComponent: te,
|
|
665
687
|
getCurrentPath: () => t.currentRoute.value.path,
|
|
666
688
|
push: (o) => {
|
|
667
689
|
t.push(o.path).catch(() => {
|
|
@@ -679,19 +701,19 @@ function ue(t, e, a) {
|
|
|
679
701
|
};
|
|
680
702
|
}
|
|
681
703
|
export {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
704
|
+
me as FormatService,
|
|
705
|
+
Z as I18nDefaultLocaleKey,
|
|
706
|
+
ne as I18nGroup,
|
|
707
|
+
E as I18nInjectionKey,
|
|
708
|
+
ae as I18nLink,
|
|
709
|
+
G as I18nLocalesKey,
|
|
710
|
+
re as I18nSwitcher,
|
|
711
|
+
oe as I18nT,
|
|
712
|
+
ie as VueI18n,
|
|
713
|
+
he as createI18n,
|
|
714
|
+
ge as createVueRouterAdapter,
|
|
715
|
+
ve as defaultPlural,
|
|
716
|
+
be as interpolate,
|
|
717
|
+
le as useI18n,
|
|
718
|
+
de as useLocaleHead
|
|
697
719
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/vue",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@i18n-micro/core": "1.
|
|
23
|
-
"@i18n-micro/types": "1.1
|
|
22
|
+
"@i18n-micro/core": "1.3.0",
|
|
23
|
+
"@i18n-micro/types": "1.2.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"vue": "^3.5.25",
|