@i18n-micro/vue 1.2.1 → 1.3.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.
@@ -29,12 +29,10 @@ export declare class VueI18n extends BaseI18n {
29
29
  addTranslations(locale: string, translations: Translations, merge?: boolean): void;
30
30
  addRouteTranslations(locale: string, routeName: string, translations: Translations, merge?: boolean): void;
31
31
  mergeTranslations(locale: string, routeName: string, translations: Translations): void;
32
- mergeGlobalTranslations(locale: string, translations: Translations): void;
33
32
  clearCache(): void;
34
33
  subscribeToChanges(cb: () => void): () => void;
35
34
  private notifyListeners;
36
35
  getAllTranslations(): Record<string, Translations>;
37
36
  getStorage(): TranslationStorage;
38
- getGeneralCache(): Record<string, Translations>;
39
37
  getRouteCache(): Record<string, Translations>;
40
38
  }
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=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=r.defineComponent({name:"I18nGroup",props:{prefix:{type:String,required:!0},groupClass:{type:String,default:""}},setup(t,{slots:e}){const n=r.inject(I);if(!n)throw new Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");const o=(u,l)=>n.t(`${t.prefix}.${u}`,l,void 0,n.getRoute());return()=>r.h("div",{class:["i18n-group",t.groupClass]},e.default?.({prefix:t.prefix,t:o}))}}),G=r.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 n=r.inject(I),o=r.inject($,void 0);if(!n)throw new Error("[i18n-micro] I18nLink: i18n instance not found. Make sure i18n plugin is installed.");const u=r.computed(()=>typeof t.to=="string"?/^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to):!1),l=r.computed(()=>{if(u.value)return t.to;if(t.localeRoute){const a=t.localeRoute(t.to);return typeof a=="string"?a:a.path||"/"}if(!o?.resolvePath)return typeof t.to=="string"?t.to:t.to.path||"/";const i=o.resolvePath(t.to,n.locale.value);return typeof i=="string"?i:i.path||"/"}),d=r.computed(()=>{if(u.value||!o)return!1;const i=o.getCurrentPath().replace(/\/$/,""),a=l.value.replace(/\/$/,"");return i===a}),h=r.computed(()=>d.value?t.activeStyle:{});return()=>u.value?r.h("a",{href:l.value,target:"_blank",rel:"noopener noreferrer",style:h.value},e.default?.()):o?.linkComponent?r.h(o.linkComponent,{to:l.value,style:h.value},{default:e.default}):r.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?.())}}),W=r.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 n=r.inject(I),o=r.inject($,void 0),u=r.inject(N,void 0);if(!n)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=r.computed(()=>t.locales||u||[]),d=r.computed(()=>t.currentLocale!==void 0?typeof t.currentLocale=="function"?t.currentLocale():t.currentLocale:n.locale.value),h=r.computed(()=>t.getLocaleName?t.getLocaleName()||null:l.value.find(m=>m.code===n.locale.value)?.displayName||null),i=r.ref(!1),a=r.ref(null),c=s=>{s&&(s.stopPropagation(),s.preventDefault()),i.value=!i.value},f=s=>t.customLabels[s.code]||s.displayName||s.code,p=r.computed(()=>{const s=l.value.find(m=>m.code===d.value);return s?f(s):h.value||d.value}),k=async s=>{if(i.value=!1,await r.nextTick(),t.switchLocale){t.switchLocale(s);return}if(n.locale.value=s,!o)return;const m=o.getCurrentPath(),b=t.localeRoute?(()=>{const g=t.localeRoute(m,s);return typeof g=="string"?g:g.path||"/"})():o?.resolvePath?(()=>{const g=o.resolvePath(m,s);return typeof g=="string"?g:g.path||"/"})():m;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 m=s.target;if(!m||!a.value)return;const b=a.value.contains(m),g=m.closest(".i18n-switcher-button")!==null;!b&&!g&&(i.value=!1)};return r.onMounted(()=>{document.addEventListener("click",H)}),r.onUnmounted(()=>{document.removeEventListener("click",H)}),()=>{const s=[];e["before-button"]&&s.push(...v(e["before-button"]()));const m=[];if(e["before-selected-locale"]&&m.push(...v(e["before-selected-locale"]())),m.push(r.h("span",p.value)),e["after-selected-locale"]&&m.push(...v(e["after-selected-locale"]())),m.push(r.h("span",{style:{...D,...i.value?M:{},...t.customIconStyle}},"▼")),s.push(r.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},m)),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:"/",y=t.localeRoute?t.localeRoute(x,g.code):o?.resolvePath?o.resolvePath(x,g.code):x,_=typeof y=="string"?y:y.path||"#",O=g.code===d.value;C.push(r.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(r.h("li",{key:g.code,style:{...j,...t.customItemStyle}},C))}),e["after-dropdown-items"]&&b.push(...v(e["after-dropdown-items"]())),s.push(r.h("ul",{class:"i18n-switcher-dropdown",style:{...R,...t.customDropdownStyle}},b))}return e["after-dropdown"]&&s.push(...v(e["after-dropdown"]())),r.h("div",{ref:a,class:"i18n-switcher-wrapper",style:{...S,...t.customWrapperStyle}},s)}}}),q=r.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:n}){const o=r.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 a=Number(t.number),c=o.tn(a),f=o.t(t.keypath,{number:c,...t.params},void 0,l);return r.h(t.tag,{...n,innerHTML:f})}if(t.date!==void 0){const a=o.td(t.date),c=o.t(t.keypath,{date:a,...t.params},void 0,l);return r.h(t.tag,{...n,innerHTML:c})}if(t.relativeDate!==void 0){const a=o.tdr(t.relativeDate),c=o.t(t.keypath,{relativeDate:a,...t.params},void 0,l);return r.h(t.tag,{...n,innerHTML:c})}if(t.plural!==void 0){const a=Number.parseInt(t.plural.toString(),10);if(t.customPluralRule){const c=t.customPluralRule(t.keypath,a,t.params,o.locale.value,(f,p,k)=>o.t(f,p,k,l));return r.h(t.tag,{...n,innerHTML:c||""})}else{const c=o.tc(t.keypath,{count:a,...t.params});return r.h(t.tag,{...n,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 r.h(t.tag,{...n,innerHTML:d});if(e.default)return r.h(t.tag,n,e.default({translation:d}));const h=[];let i=0;for(const[a,c]of Object.entries(e)){if(a==="default")continue;const f=`{${a}}`,p=d.indexOf(f,i);p!==-1&&(p>i&&h.push(d.slice(i,p)),c&&h.push(r.h(c)),i=p+f.length)}return i<d.length&&h.push(d.slice(i)),e.default?r.h(t.tag,n,e.default({children:h})):h.length>0?r.h(t.tag,n,h):r.h(t.tag,n,d)}}});function B(t){const e=r.inject(I),n=r.inject($,void 0),o=r.inject(N,void 0),u=r.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,a)=>n?.resolvePath?n.resolvePath(i,a||e.locale.value):i;return{instance:e,locale:r.computed({get:()=>e.locale.value,set:i=>{e.locale.value=i}}),getLocales:()=>l,defaultLocale:()=>d,getLocaleName:()=>l.find(a=>a.code===e.locale.value)?.displayName||null,localeRoute:h,localePath:(i,a)=>{const c=h(i,a);return typeof c=="string"?c:c.path||"/"},switchLocale:i=>{if(e.locale.value=i,n){const a=n.getCurrentPath(),c=h(a,i);n.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),mergeGlobalTranslations:e.mergeGlobalTranslations.bind(e),clearCache:e.clearCache.bind(e)}}function J(t={}){const{addDirAttribute:e=!0,identifierAttribute:n="id",addSeoAttributes:o=!0,baseUrl:u="/"}=t,{getLocale:l,getLocales:d,localeRoute:h}=B(),i=r.inject($,void 0),a=r.ref({htmlAttrs:{},link:[],meta:[]});function c(p,k){const S=new URL(p,"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(p=[]){if(!i){a.value={htmlAttrs:{},link:[],meta:[]};return}const k=l(),S=d(),P=S.find(y=>y.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(y=>K[0]===y.code);let M=L,v;D?(M=L.slice(D.code.length+1)||"/",v=c(M,p)):v=c(L,p);const s=`${typeof u=="function"?u():u}${v.startsWith("/")?"":"/"}${v}`;if(a.value={htmlAttrs:{lang:R,...e?{dir:j}:{}},link:[],meta:[]},!o)return;const m=S,b={[n]:"i18n-og",property:"og:locale",content:R},g={[n]:"i18n-og-url",property:"og:url",content:s},C=m.map(y=>({[n]:`i18n-og-alt-${y.iso||y.code}`,property:"og:locale:alternate",content:y.iso||y.code})),T={[n]:"i18n-can",rel:"canonical",href:s},x=m.flatMap(y=>{if(!h||!i)return[];const _=i.getCurrentPath(),O=h(_,y.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=[{[n]:`i18n-alternate-${y.code}`,rel:"alternate",href:A,hreflang:y.code}];return y.iso&&y.iso!==y.code&&V.push({[n]:`i18n-alternate-${y.iso}`,rel:"alternate",href:A,hreflang:y.iso}),V});a.value.meta=[b,g,...C],a.value.link=[T,...x]}return{metaObject:a,updateMeta:f}}class z extends E.BaseI18n{constructor(e){const n={translations:new Map};if(super({storage:n,plural:e.plural,missingWarn:e.missingWarn,missingHandler:e.missingHandler}),this.listeners=new Set,this.storage=n,this._locale=r.shallowRef(e.locale),this._fallbackLocale=r.shallowRef(e.fallbackLocale||e.locale),this._currentRoute=r.shallowRef("general"),this._revision=r.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,n,o=!0){super.loadTranslationsCore(e,n,o),this._revision.value++,this.notifyListeners()}addRouteTranslations(e,n,o,u=!0){super.loadRouteTranslationsCore(e,n,o,u),this._revision.value++,this.notifyListeners()}mergeTranslations(e,n,o){this.helper.mergeTranslation(e,n,o,!0),this._revision.value++,this.notifyListeners()}mergeGlobalTranslations(e,n){this.helper.mergeGlobalTranslation(e,n,!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[n,o]of this.storage.translations)if(!n.includes(":"))e[n]=o;else{const u=n.split(":")[0];u&&(e[u]||(e[u]={}),Object.assign(e[u],o))}return e}getStorage(){return this.storage}getGeneralCache(){const e={};for(const[n,o]of this.storage.translations)n.includes(":")||(e[n]=o);return e}getRouteCache(){const e={};for(const[n,o]of this.storage.translations)n.includes(":")&&(e[n]=o);return e}}function Q(t){const{routingStrategy:e,locales:n,defaultLocale:o,...u}=t,l=new z(u);let d=null,h=e||null;return{global:l,setRoutingStrategy:a=>{h=a,d&&d.provide($,a)},install(a){d=a,a.provide(I,l),h&&a.provide($,h),n&&a.provide(N,n),o&&a.provide(U,o),a.config.globalProperties.$t=(c,f,p,k)=>l.t(c,f,p,k),a.config.globalProperties.$ts=(c,f,p,k)=>l.ts(c,f,p,k),a.config.globalProperties.$tc=(c,f,p)=>l.tc(c,f,p),a.config.globalProperties.$tn=(c,f)=>l.tn(c,f),a.config.globalProperties.$td=(c,f)=>l.td(c,f),a.config.globalProperties.$tdr=(c,f)=>l.tdr(c,f),a.config.globalProperties.$has=(c,f)=>l.has(c,f),a.config.globalProperties.$i18n=l,a.component("I18nT",q),a.component("I18nLink",G),a.component("I18nGroup",F),a.component("I18nSwitcher",W)}}}function X(t,e,n){const o=e.map(l=>l.code),u=(l,d)=>{const i=(typeof l=="string"?l:l.path||"/").split("/").filter(Boolean),a=i[0];a!==void 0&&o.includes(a)&&i.shift();const c=`/${i.join("/")}`;return d===n?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=G;exports.I18nLocalesKey=N;exports.I18nSwitcher=W;exports.I18nT=q;exports.VueI18n=z;exports.createI18n=Q;exports.createVueRouterAdapter=X;exports.useI18n=B;exports.useLocaleHead=J;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("vue"),H=require("@i18n-micro/core"),Q=require("vue-router"),$=Symbol("i18n"),K=Symbol("i18n-locales"),U=Symbol("i18n-default-locale"),_=Symbol("i18n-router-strategy"),q=a.defineComponent({name:"I18nGroup",props:{prefix:{type:String,required:!0},groupClass:{type:String,default:""}},setup(t,{slots:e}){const r=a.inject($);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}))}}),B=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($),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?.())}}),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($),o=a.inject(_,void 0),u=a.inject(K,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(),L=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:L})},P={position:"relative",display:"inline-block",verticalAlign:"middle"},R={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"},j={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)"},x={margin:"0",padding:"0"},k={display:"block",padding:"8px 12px",color:"#333",textDecoration:"none",transition:"background-color 0.3s ease",cursor:"pointer"},V={fontWeight:"bold",color:"#007bff"},N={marginLeft:"8px",display:"inline-block",transition:"transform 0.3s ease"},W={transform:"rotate(180deg)"},v=s=>s?Array.isArray(s)?s:[s]:[],C=s=>{if(!i.value)return;const y=s.target;if(!y||!n.value)return;const L=n.value.contains(y),p=y.closest(".i18n-switcher-button")!==null;!L&&!p&&(i.value=!1)};return a.onMounted(()=>{document.addEventListener("click",C)}),a.onUnmounted(()=>{document.removeEventListener("click",C)}),()=>{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:{...N,...i.value?W:{},...t.customIconStyle}},"▼")),s.push(a.h("button",{class:"i18n-switcher-button",style:{...R,...t.customButtonStyle},onClick:L=>{L.preventDefault(),L.stopPropagation(),c(L)},type:"button",ariaHaspopup:!0,ariaExpanded:i.value},y)),e["before-dropdown"]&&s.push(...v(e["before-dropdown"]())),i.value){const L=[];e["before-dropdown-items"]&&L.push(...v(e["before-dropdown-items"]())),l.value.forEach(p=>{const T=[];e["before-item"]&&T.push(...v(e["before-item"]({locale:p})));const D=[];e["before-link-content"]&&D.push(...v(e["before-link-content"]({locale:p}))),D.push(g(p)),e["after-link-content"]&&D.push(...v(e["after-link-content"]({locale:p})));const A=typeof window<"u"?window.location.pathname:"/",O=t.localeRoute?t.localeRoute(A,p.code):o?.resolvePath?o.resolvePath(A,p.code):A,M=typeof O=="string"?O:O.path||"#",f=p.code===d.value;T.push(a.h("a",{class:`switcher-locale-${p.code}`,href:typeof M=="string"?M:"#",style:{...k,...f?V:{},...t.customLinkStyle},onClick:I=>{I.preventDefault(),I.stopPropagation(),b(p.code)}},D)),e["after-item"]&&T.push(...v(e["after-item"]({locale:p}))),L.push(a.h("li",{key:p.code,style:{...x,...t.customItemStyle}},T))}),e["after-dropdown-items"]&&L.push(...v(e["after-dropdown-items"]())),s.push(a.h("ul",{class:"i18n-switcher-dropdown",style:{...j,...t.customDropdownStyle}},L))}return e["after-dropdown"]&&s.push(...v(e["after-dropdown"]())),a.h("div",{ref:n,class:"i18n-switcher-wrapper",style:{...P,...t.customWrapperStyle}},s)}}}),G=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($);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 Z(t){const e=a.inject($),r=a.inject(_,void 0),o=a.inject(K,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 X(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,b){const P=new URL(m,"http://localhost"),R=new URLSearchParams(P.search),j={};for(const k of b)R.has(k)&&(j[k]=R.get(k));const x=new URLSearchParams(j);return x.toString()?`${P.pathname}?${x.toString()}`:P.pathname}function g(m=[]){if(!i){n.value={htmlAttrs:{},link:[],meta:[]};return}const b=l(),P=d(),R=P.find(f=>f.code===b);if(!R)return;const j=R.iso||b,x=R.dir||"auto";let k=i.getCurrentPath();k.startsWith("/")||(k=`/${k}`);const V=k.split("/").filter(Boolean),N=P.find(f=>V[0]===f.code);let W=k,v,C;const s=typeof u=="function"?u():u;if(N){W=k.slice(N.code.length+1)||"/",v=c(W,m);const f=`/${b}`;C=`${s}${f}${v.startsWith("/")?"":"/"}${v}`}else v=c(k,m),C=`${s}${v.startsWith("/")?"":"/"}${v}`;if(n.value={htmlAttrs:{lang:j,...e?{dir:x}:{}},link:[],meta:[]},!o)return;const y=P.filter(f=>!f.disabled),L={[r]:"i18n-og",property:"og:locale",content:j},p={[r]:"i18n-og-url",property:"og:url",content:C},T=y.filter(f=>f.code!==b).map(f=>({[r]:`i18n-og-alt-${f.iso||f.code}`,property:"og:locale:alternate",content:f.iso||f.code})),D={[r]:"i18n-can",rel:"canonical",href:C},A=y.flatMap(f=>{if(!h||!i)return[];const I=i.getCurrentPath(),S=h(I,f.code),w=typeof S=="string"?S:S?.path||"/";if(!w)return[];let E;w.startsWith("http://")||w.startsWith("https://")?E=w:E=`${typeof u=="function"?u():u}${w.startsWith("/")?"":"/"}${w}`;const F=[{[r]:`i18n-alternate-${f.code}`,rel:"alternate",href:E,hreflang:f.code}];return f.iso&&f.iso!==f.code&&F.push({[r]:`i18n-alternate-${f.iso}`,rel:"alternate",href:E,hreflang:f.iso}),F}),O=a.inject(U,void 0);let M=null;if(h&&i&&O){const f=i.getCurrentPath(),I=h(f,O),S=typeof I=="string"?I:I?.path||"/";if(S){let w;S.startsWith("http://")||S.startsWith("https://")?w=S:w=`${typeof u=="function"?u():u}${S.startsWith("/")?"":"/"}${S}`,M={[r]:"i18n-xd",rel:"alternate",href:w,hreflang:"x-default"}}}n.value.meta=[L,p,...T],n.value.link=[D,...A,...M?[M]:[]]}return{metaObject:n,updateMeta:g}}class J extends H.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 Y(t){const{routingStrategy:e,locales:r,defaultLocale:o,...u}=t,l=new J(u);let d=null,h=e||null;return{global:l,setRoutingStrategy:n=>{h=n,d&&d.provide(_,n)},install(n){d=n,n.provide($,l),h&&n.provide(_,h),r&&n.provide(K,r),o&&n.provide(U,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",G),n.component("I18nLink",B),n.component("I18nGroup",q),n.component("I18nSwitcher",z)}}}function ee(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:Q.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:()=>H.FormatService});Object.defineProperty(exports,"defaultPlural",{enumerable:!0,get:()=>H.defaultPlural});Object.defineProperty(exports,"interpolate",{enumerable:!0,get:()=>H.interpolate});exports.I18nDefaultLocaleKey=U;exports.I18nGroup=q;exports.I18nInjectionKey=$;exports.I18nLink=B;exports.I18nLocalesKey=K;exports.I18nSwitcher=z;exports.I18nT=G;exports.VueI18n=J;exports.createI18n=Y;exports.createVueRouterAdapter=ee;exports.useI18n=Z;exports.useLocaleHead=X;
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { defineComponent as H, inject as S, h as g, computed as R, ref as G, onMounted as z, onUnmounted as q, nextTick as Z, shallowRef as U } from "vue";
2
- import { BaseI18n as J } from "@i18n-micro/core";
3
- import { FormatService as he, defaultPlural as ge, interpolate as ye } from "@i18n-micro/core";
4
- import { RouterLink as Q } from "vue-router";
5
- const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-locales"), B = /* @__PURE__ */ Symbol("i18n-default-locale"), j = /* @__PURE__ */ Symbol("i18n-router-strategy"), X = H({
1
+ import { defineComponent as F, inject as S, h as y, computed as $, ref as B, onMounted as Z, onUnmounted as J, nextTick as Q, shallowRef as V } from "vue";
2
+ import { BaseI18n as X } from "@i18n-micro/core";
3
+ import { FormatService as ye, defaultPlural as pe, interpolate as me } from "@i18n-micro/core";
4
+ import { RouterLink as Y } from "vue-router";
5
+ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__PURE__ */ Symbol("i18n-locales"), q = /* @__PURE__ */ Symbol("i18n-default-locale"), A = /* @__PURE__ */ Symbol("i18n-router-strategy"), ee = F({
6
6
  name: "I18nGroup",
7
7
  props: {
8
8
  prefix: {
@@ -15,11 +15,11 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
15
15
  }
16
16
  },
17
17
  setup(t, { slots: e }) {
18
- const n = S(D);
19
- if (!n)
18
+ const a = S(E);
19
+ if (!a)
20
20
  throw new Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");
21
- const r = (c, o) => n.t(`${t.prefix}.${c}`, o, void 0, n.getRoute());
22
- return () => g(
21
+ const r = (c, o) => a.t(`${t.prefix}.${c}`, o, void 0, a.getRoute());
22
+ return () => y(
23
23
  "div",
24
24
  {
25
25
  class: ["i18n-group", t.groupClass]
@@ -27,7 +27,7 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
27
27
  e.default?.({ prefix: t.prefix, t: r })
28
28
  );
29
29
  }
30
- }), Y = H({
30
+ }), te = F({
31
31
  name: "I18nLink",
32
32
  props: {
33
33
  to: {
@@ -44,47 +44,47 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
44
44
  }
45
45
  },
46
46
  setup(t, { slots: e }) {
47
- const n = S(D), r = S(j, void 0);
48
- if (!n)
47
+ const a = S(E), r = S(A, void 0);
48
+ if (!a)
49
49
  throw new Error("[i18n-micro] I18nLink: i18n instance not found. Make sure i18n plugin is installed.");
50
- const c = R(() => typeof t.to == "string" ? /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to) : !1), o = R(() => {
50
+ const c = $(() => typeof t.to == "string" ? /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to) : !1), o = $(() => {
51
51
  if (c.value)
52
52
  return t.to;
53
53
  if (t.localeRoute) {
54
- const a = t.localeRoute(t.to);
55
- return typeof a == "string" ? a : a.path || "/";
54
+ const n = t.localeRoute(t.to);
55
+ return typeof n == "string" ? n : n.path || "/";
56
56
  }
57
57
  if (!r?.resolvePath)
58
58
  return typeof t.to == "string" ? t.to : t.to.path || "/";
59
- const l = r.resolvePath(t.to, n.locale.value);
59
+ const l = r.resolvePath(t.to, a.locale.value);
60
60
  return typeof l == "string" ? l : l.path || "/";
61
- }), u = R(() => {
61
+ }), u = $(() => {
62
62
  if (c.value || !r)
63
63
  return !1;
64
- const l = r.getCurrentPath().replace(/\/$/, ""), a = o.value.replace(/\/$/, "");
65
- return l === a;
66
- }), f = R(() => u.value ? t.activeStyle : {});
67
- return () => c.value ? g(
64
+ const l = r.getCurrentPath().replace(/\/$/, ""), n = o.value.replace(/\/$/, "");
65
+ return l === n;
66
+ }), d = $(() => 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: f.value
73
+ style: d.value
74
74
  },
75
75
  e.default?.()
76
- ) : r?.linkComponent ? g(
76
+ ) : r?.linkComponent ? y(
77
77
  r.linkComponent,
78
78
  {
79
79
  to: o.value,
80
- style: f.value
80
+ style: d.value
81
81
  },
82
82
  { default: e.default }
83
- ) : g(
83
+ ) : y(
84
84
  "a",
85
85
  {
86
86
  href: o.value,
87
- style: f.value,
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"), K = /* @__PURE__ */ Symbol("i18n-local
92
92
  e.default?.()
93
93
  );
94
94
  }
95
- }), ee = H({
95
+ }), ne = F({
96
96
  name: "I18nSwitcher",
97
97
  props: {
98
98
  customLabels: {
@@ -153,38 +153,38 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
153
153
  }
154
154
  },
155
155
  setup(t, { slots: e }) {
156
- const n = S(D), r = S(j, void 0), c = S(K, void 0);
157
- if (!n)
156
+ const a = S(E), r = S(A, void 0), c = S(z, void 0);
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 = R(() => t.locales || c || []), u = R(() => t.currentLocale !== void 0 ? typeof t.currentLocale == "function" ? t.currentLocale() : t.currentLocale : n.locale.value), f = R(() => t.getLocaleName ? t.getLocaleName() || null : o.value.find((y) => y.code === n.locale.value)?.displayName || null), l = G(!1), a = G(null), i = (s) => {
163
+ const o = $(() => t.locales || c || []), u = $(() => t.currentLocale !== void 0 ? typeof t.currentLocale == "function" ? t.currentLocale() : t.currentLocale : a.locale.value), d = $(() => t.getLocaleName ? t.getLocaleName() || null : o.value.find((p) => p.code === a.locale.value)?.displayName || null), l = B(!1), n = B(null), i = (s) => {
164
164
  s && (s.stopPropagation(), s.preventDefault()), l.value = !l.value;
165
- }, d = (s) => t.customLabels[s.code] || s.displayName || s.code, p = R(() => {
166
- const s = o.value.find((y) => y.code === u.value);
167
- return s ? d(s) : f.value || u.value;
168
- }), k = async (s) => {
169
- if (l.value = !1, await Z(), t.switchLocale) {
165
+ }, h = (s) => t.customLabels[s.code] || s.displayName || s.code, m = $(() => {
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 Q(), t.switchLocale) {
170
170
  t.switchLocale(s);
171
171
  return;
172
172
  }
173
- if (n.locale.value = s, !r)
173
+ if (a.locale.value = s, !r)
174
174
  return;
175
- const y = r.getCurrentPath(), b = t.localeRoute ? (() => {
176
- const h = t.localeRoute(y, s);
177
- return typeof h == "string" ? h : h.path || "/";
175
+ const p = r.getCurrentPath(), L = t.localeRoute ? (() => {
176
+ const g = t.localeRoute(p, s);
177
+ return typeof g == "string" ? g : g.path || "/";
178
178
  })() : r?.resolvePath ? (() => {
179
- const h = r.resolvePath(y, s);
180
- return typeof h == "string" ? h : h.path || "/";
181
- })() : y;
182
- r.push({ path: b });
183
- }, w = {
179
+ const g = r.resolvePath(p, s);
180
+ return typeof g == "string" ? g : g.path || "/";
181
+ })() : p;
182
+ r.push({ path: L });
183
+ }, R = {
184
184
  position: "relative",
185
185
  display: "inline-block",
186
186
  verticalAlign: "middle"
187
- }, C = {
187
+ }, x = {
188
188
  padding: "4px 12px",
189
189
  fontSize: "16px",
190
190
  cursor: "pointer",
@@ -206,126 +206,126 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__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
- }, T = {
209
+ }, D = {
210
210
  margin: "0",
211
211
  padding: "0"
212
- }, L = {
212
+ }, k = {
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
- }, W = {
219
+ }, K = {
220
220
  fontWeight: "bold",
221
221
  color: "#007bff"
222
- }, _ = {
222
+ }, U = {
223
223
  marginLeft: "8px",
224
224
  display: "inline-block",
225
225
  transition: "transform 0.3s ease"
226
- }, A = {
226
+ }, H = {
227
227
  transform: "rotate(180deg)"
228
- }, v = (s) => s ? Array.isArray(s) ? s : [s] : [], F = (s) => {
228
+ }, v = (s) => s ? Array.isArray(s) ? s : [s] : [], T = (s) => {
229
229
  if (!l.value) return;
230
- const y = s.target;
231
- if (!y || !a.value) return;
232
- const b = a.value.contains(y), h = y.closest(".i18n-switcher-button") !== null;
233
- !b && !h && (l.value = !1);
230
+ const p = s.target;
231
+ if (!p || !n.value) return;
232
+ const L = n.value.contains(p), g = p.closest(".i18n-switcher-button") !== null;
233
+ !L && !g && (l.value = !1);
234
234
  };
235
- return z(() => {
236
- document.addEventListener("click", F);
237
- }), q(() => {
238
- document.removeEventListener("click", F);
235
+ return Z(() => {
236
+ document.addEventListener("click", T);
237
+ }), J(() => {
238
+ document.removeEventListener("click", T);
239
239
  }), () => {
240
240
  const s = [];
241
241
  e["before-button"] && s.push(...v(e["before-button"]()));
242
- const y = [];
243
- if (e["before-selected-locale"] && y.push(...v(e["before-selected-locale"]())), y.push(g("span", p.value)), e["after-selected-locale"] && y.push(...v(e["after-selected-locale"]())), y.push(
244
- g(
242
+ const p = [];
243
+ if (e["before-selected-locale"] && p.push(...v(e["before-selected-locale"]())), p.push(y("span", m.value)), e["after-selected-locale"] && p.push(...v(e["after-selected-locale"]())), p.push(
244
+ y(
245
245
  "span",
246
246
  {
247
247
  style: {
248
- ..._,
249
- ...l.value ? A : {},
248
+ ...U,
249
+ ...l.value ? H : {},
250
250
  ...t.customIconStyle
251
251
  }
252
252
  },
253
253
  "▼"
254
254
  )
255
255
  ), s.push(
256
- g(
256
+ y(
257
257
  "button",
258
258
  {
259
259
  class: "i18n-switcher-button",
260
- style: { ...C, ...t.customButtonStyle },
261
- onClick: (b) => {
262
- b.preventDefault(), b.stopPropagation(), i(b);
260
+ style: { ...x, ...t.customButtonStyle },
261
+ onClick: (L) => {
262
+ L.preventDefault(), L.stopPropagation(), i(L);
263
263
  },
264
264
  type: "button",
265
265
  ariaHaspopup: !0,
266
266
  ariaExpanded: l.value
267
267
  },
268
- y
268
+ p
269
269
  )
270
270
  ), e["before-dropdown"] && s.push(...v(e["before-dropdown"]())), l.value) {
271
- const b = [];
272
- e["before-dropdown-items"] && b.push(...v(e["before-dropdown-items"]())), o.value.forEach((h) => {
273
- const x = [];
274
- e["before-item"] && x.push(...v(e["before-item"]({ locale: h })));
275
- const $ = [];
276
- e["before-link-content"] && $.push(...v(e["before-link-content"]({ locale: h }))), $.push(d(h)), e["after-link-content"] && $.push(...v(e["after-link-content"]({ locale: h })));
277
- const O = typeof window < "u" ? window.location.pathname : "/", m = t.localeRoute ? t.localeRoute(O, h.code) : r?.resolvePath ? r.resolvePath(O, h.code) : O, E = typeof m == "string" ? m : m.path || "#", M = h.code === u.value;
278
- x.push(
279
- g(
271
+ const L = [];
272
+ e["before-dropdown-items"] && L.push(...v(e["before-dropdown-items"]())), o.value.forEach((g) => {
273
+ const j = [];
274
+ e["before-item"] && j.push(...v(e["before-item"]({ locale: g })));
275
+ const O = [];
276
+ e["before-link-content"] && O.push(...v(e["before-link-content"]({ locale: g }))), O.push(h(g)), e["after-link-content"] && O.push(...v(e["after-link-content"]({ locale: g })));
277
+ const N = typeof window < "u" ? window.location.pathname : "/", M = t.localeRoute ? t.localeRoute(N, g.code) : r?.resolvePath ? r.resolvePath(N, g.code) : N, _ = typeof M == "string" ? M : M.path || "#", f = g.code === u.value;
278
+ j.push(
279
+ y(
280
280
  "a",
281
281
  {
282
- class: `switcher-locale-${h.code}`,
283
- href: typeof E == "string" ? E : "#",
282
+ class: `switcher-locale-${g.code}`,
283
+ href: typeof _ == "string" ? _ : "#",
284
284
  style: {
285
- ...L,
286
- ...M ? W : {},
285
+ ...k,
286
+ ...f ? K : {},
287
287
  ...t.customLinkStyle
288
288
  },
289
- // Предотвращаем стандартную навигацию, используем только handleSwitchLocale
290
- onClick: (P) => {
291
- P.preventDefault(), P.stopPropagation(), k(h.code);
289
+ // Prevent default navigation, use only handleSwitchLocale
290
+ onClick: (C) => {
291
+ C.preventDefault(), C.stopPropagation(), b(g.code);
292
292
  }
293
293
  },
294
- $
294
+ O
295
295
  )
296
- ), e["after-item"] && x.push(...v(e["after-item"]({ locale: h }))), b.push(
297
- g(
296
+ ), e["after-item"] && j.push(...v(e["after-item"]({ locale: g }))), L.push(
297
+ y(
298
298
  "li",
299
299
  {
300
- key: h.code,
301
- style: { ...T, ...t.customItemStyle }
300
+ key: g.code,
301
+ style: { ...D, ...t.customItemStyle }
302
302
  },
303
- x
303
+ j
304
304
  )
305
305
  );
306
- }), e["after-dropdown-items"] && b.push(...v(e["after-dropdown-items"]())), s.push(
307
- g(
306
+ }), e["after-dropdown-items"] && L.push(...v(e["after-dropdown-items"]())), s.push(
307
+ y(
308
308
  "ul",
309
309
  {
310
310
  class: "i18n-switcher-dropdown",
311
311
  style: { ...I, ...t.customDropdownStyle }
312
312
  },
313
- b
313
+ L
314
314
  )
315
315
  );
316
316
  }
317
- return e["after-dropdown"] && s.push(...v(e["after-dropdown"]())), g(
317
+ return e["after-dropdown"] && s.push(...v(e["after-dropdown"]())), y(
318
318
  "div",
319
319
  {
320
- ref: a,
320
+ ref: n,
321
321
  class: "i18n-switcher-wrapper",
322
- style: { ...w, ...t.customWrapperStyle }
322
+ style: { ...R, ...t.customWrapperStyle }
323
323
  },
324
324
  s
325
325
  );
326
326
  };
327
327
  }
328
- }), te = H({
328
+ }), ae = F({
329
329
  name: "I18nT",
330
330
  props: {
331
331
  keypath: {
@@ -369,72 +369,72 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
369
369
  type: [Date, String, Number]
370
370
  }
371
371
  },
372
- setup(t, { slots: e, attrs: n }) {
373
- const r = S(D);
372
+ setup(t, { slots: e, attrs: a }) {
373
+ const r = S(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 a = Number(t.number), i = r.tn(a), d = r.t(t.keypath, { number: i, ...t.params }, void 0, o);
380
- return g(t.tag, { ...n, innerHTML: d });
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
- const a = r.td(t.date), i = r.t(t.keypath, { date: a, ...t.params }, void 0, o);
384
- return g(t.tag, { ...n, innerHTML: i });
383
+ const n = r.td(t.date), i = r.t(t.keypath, { date: n, ...t.params }, void 0, o);
384
+ return y(t.tag, { ...a, innerHTML: i });
385
385
  }
386
386
  if (t.relativeDate !== void 0) {
387
- const a = r.tdr(t.relativeDate), i = r.t(t.keypath, { relativeDate: a, ...t.params }, void 0, o);
388
- return g(t.tag, { ...n, innerHTML: i });
387
+ const n = r.tdr(t.relativeDate), i = r.t(t.keypath, { relativeDate: n, ...t.params }, void 0, o);
388
+ return y(t.tag, { ...a, innerHTML: i });
389
389
  }
390
390
  if (t.plural !== void 0) {
391
- const a = Number.parseInt(t.plural.toString(), 10);
391
+ const n = Number.parseInt(t.plural.toString(), 10);
392
392
  if (t.customPluralRule) {
393
393
  const i = t.customPluralRule(
394
394
  t.keypath,
395
- a,
395
+ n,
396
396
  t.params,
397
397
  r.locale.value,
398
- (d, p, k) => r.t(d, p, k, o)
398
+ (h, m, b) => r.t(h, m, b, o)
399
399
  );
400
- return g(t.tag, { ...n, innerHTML: i || "" });
400
+ return y(t.tag, { ...a, innerHTML: i || "" });
401
401
  } else {
402
- const i = r.tc(t.keypath, { count: a, ...t.params });
403
- return g(t.tag, { ...n, innerHTML: i });
402
+ const i = r.tc(t.keypath, { count: n, ...t.params });
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 g(t.tag, { ...n, innerHTML: u });
410
+ return y(t.tag, { ...a, innerHTML: u });
411
411
  if (e.default)
412
- return g(t.tag, n, e.default({ translation: u }));
413
- const f = [];
412
+ return y(t.tag, a, e.default({ translation: u }));
413
+ const d = [];
414
414
  let l = 0;
415
- for (const [a, i] of Object.entries(e)) {
416
- if (a === "default") continue;
417
- const d = `{${a}}`, p = u.indexOf(d, l);
418
- p !== -1 && (p > l && f.push(u.slice(l, p)), i && f.push(g(i)), l = p + d.length);
415
+ for (const [n, i] of Object.entries(e)) {
416
+ if (n === "default") continue;
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 && f.push(u.slice(l)), e.default ? g(t.tag, n, e.default({ children: f })) : f.length > 0 ? g(t.tag, n, f) : g(t.tag, n, u);
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 ne(t) {
425
- const e = S(D), n = S(j, void 0), r = S(K, void 0), c = S(B, void 0);
424
+ function re(t) {
425
+ const e = S(E), a = S(A, void 0), r = S(z, void 0), c = S(q, 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, f = (l, a) => n?.resolvePath ? n.resolvePath(l, a || e.locale.value) : l;
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: R({
437
+ locale: $({
438
438
  get: () => e.locale.value,
439
439
  set: (l) => {
440
440
  e.locale.value = l;
@@ -443,17 +443,17 @@ function ne(t) {
443
443
  // Locale helpers
444
444
  getLocales: () => o,
445
445
  defaultLocale: () => u,
446
- getLocaleName: () => o.find((a) => a.code === e.locale.value)?.displayName || null,
446
+ getLocaleName: () => o.find((n) => n.code === e.locale.value)?.displayName || null,
447
447
  // Routing helpers
448
- localeRoute: f,
449
- localePath: (l, a) => {
450
- const i = f(l, a);
448
+ localeRoute: d,
449
+ localePath: (l, n) => {
450
+ const i = d(l, n);
451
451
  return typeof i == "string" ? i : i.path || "/";
452
452
  },
453
453
  switchLocale: (l) => {
454
- if (e.locale.value = l, n) {
455
- const a = n.getCurrentPath(), i = f(a, l);
456
- n.push(typeof i == "string" ? { path: i } : { path: i.path || "/" });
454
+ if (e.locale.value = l, a) {
455
+ const n = a.getCurrentPath(), i = d(n, l);
456
+ a.push(typeof i == "string" ? { path: i } : { path: i.path || "/" });
457
457
  }
458
458
  },
459
459
  // Translation methods (delegate to instance)
@@ -472,104 +472,121 @@ function ne(t) {
472
472
  addTranslations: e.addTranslations.bind(e),
473
473
  addRouteTranslations: e.addRouteTranslations.bind(e),
474
474
  mergeTranslations: e.mergeTranslations.bind(e),
475
- mergeGlobalTranslations: e.mergeGlobalTranslations.bind(e),
476
475
  clearCache: e.clearCache.bind(e)
477
476
  };
478
477
  }
479
- function ce(t = {}) {
480
- const { addDirAttribute: e = !0, identifierAttribute: n = "id", addSeoAttributes: r = !0, baseUrl: c = "/" } = t, { getLocale: o, getLocales: u, localeRoute: f } = ne(), l = S(j, void 0), a = G({
478
+ function ue(t = {}) {
479
+ const { addDirAttribute: e = !0, identifierAttribute: a = "id", addSeoAttributes: r = !0, baseUrl: c = "/" } = t, { getLocale: o, getLocales: u, localeRoute: d } = re(), l = S(A, void 0), n = B({
481
480
  htmlAttrs: {},
482
481
  link: [],
483
482
  meta: []
484
483
  });
485
- function i(p, k) {
486
- const w = new URL(p, "http://localhost"), C = new URLSearchParams(w.search), I = {};
487
- for (const L of k)
488
- C.has(L) && (I[L] = C.get(L));
489
- const T = new URLSearchParams(I);
490
- return T.toString() ? `${w.pathname}?${T.toString()}` : w.pathname;
484
+ function i(m, b) {
485
+ const R = new URL(m, "http://localhost"), x = new URLSearchParams(R.search), I = {};
486
+ for (const k of b)
487
+ x.has(k) && (I[k] = x.get(k));
488
+ const D = new URLSearchParams(I);
489
+ return D.toString() ? `${R.pathname}?${D.toString()}` : R.pathname;
491
490
  }
492
- function d(p = []) {
491
+ function h(m = []) {
493
492
  if (!l) {
494
- a.value = { htmlAttrs: {}, link: [], meta: [] };
493
+ n.value = { htmlAttrs: {}, link: [], meta: [] };
495
494
  return;
496
495
  }
497
- const k = o(), w = u(), C = w.find((m) => m.code === k);
498
- if (!C)
496
+ const b = o(), R = u(), x = R.find((f) => f.code === b);
497
+ if (!x)
499
498
  return;
500
- const I = C.iso || k, T = C.dir || "auto";
501
- let L = l.getCurrentPath();
502
- L.startsWith("/") || (L = `/${L}`);
503
- const W = L.split("/").filter(Boolean), _ = w.find((m) => W[0] === m.code);
504
- let A = L, v;
505
- _ ? (A = L.slice(_.code.length + 1) || "/", v = i(A, p)) : v = i(L, p);
506
- const s = `${typeof c == "function" ? c() : c}${v.startsWith("/") ? "" : "/"}${v}`;
507
- if (a.value = {
499
+ const I = x.iso || b, D = x.dir || "auto";
500
+ let k = l.getCurrentPath();
501
+ k.startsWith("/") || (k = `/${k}`);
502
+ const K = k.split("/").filter(Boolean), U = R.find((f) => K[0] === f.code);
503
+ let H = k, v, T;
504
+ const s = typeof c == "function" ? c() : c;
505
+ if (U) {
506
+ H = k.slice(U.code.length + 1) || "/", v = i(H, m);
507
+ const f = `/${b}`;
508
+ T = `${s}${f}${v.startsWith("/") ? "" : "/"}${v}`;
509
+ } else
510
+ v = i(k, m), T = `${s}${v.startsWith("/") ? "" : "/"}${v}`;
511
+ if (n.value = {
508
512
  htmlAttrs: {
509
513
  lang: I,
510
- ...e ? { dir: T } : {}
514
+ ...e ? { dir: D } : {}
511
515
  },
512
516
  link: [],
513
517
  meta: []
514
518
  }, !r)
515
519
  return;
516
- const y = w, b = {
517
- [n]: "i18n-og",
520
+ const p = R.filter((f) => !f.disabled), L = {
521
+ [a]: "i18n-og",
518
522
  property: "og:locale",
519
523
  content: I
520
- }, h = {
521
- [n]: "i18n-og-url",
524
+ }, g = {
525
+ [a]: "i18n-og-url",
522
526
  property: "og:url",
523
- content: s
524
- }, x = y.map((m) => ({
525
- [n]: `i18n-og-alt-${m.iso || m.code}`,
527
+ content: T
528
+ }, j = p.filter((f) => f.code !== b).map((f) => ({
529
+ [a]: `i18n-og-alt-${f.iso || f.code}`,
526
530
  property: "og:locale:alternate",
527
- content: m.iso || m.code
528
- })), $ = {
529
- [n]: "i18n-can",
531
+ content: f.iso || f.code
532
+ })), O = {
533
+ [a]: "i18n-can",
530
534
  rel: "canonical",
531
- href: s
532
- }, O = y.flatMap((m) => {
533
- if (!f || !l)
535
+ href: T
536
+ }, N = p.flatMap((f) => {
537
+ if (!d || !l)
534
538
  return [];
535
- const E = l.getCurrentPath(), M = f(E, m.code), P = typeof M == "string" ? M : M?.path || "/";
539
+ const C = l.getCurrentPath(), w = d(C, f.code), P = typeof w == "string" ? w : w?.path || "/";
536
540
  if (!P)
537
541
  return [];
538
- let N;
539
- P.startsWith("http://") || P.startsWith("https://") ? N = P : N = `${typeof c == "function" ? c() : c}${P.startsWith("/") ? "" : "/"}${P}`;
540
- const V = [
542
+ let W;
543
+ P.startsWith("http://") || P.startsWith("https://") ? W = P : W = `${typeof c == "function" ? c() : c}${P.startsWith("/") ? "" : "/"}${P}`;
544
+ const G = [
541
545
  {
542
- [n]: `i18n-alternate-${m.code}`,
546
+ [a]: `i18n-alternate-${f.code}`,
543
547
  rel: "alternate",
544
- href: N,
545
- hreflang: m.code
548
+ href: W,
549
+ hreflang: f.code
546
550
  }
547
551
  ];
548
- return m.iso && m.iso !== m.code && V.push({
549
- [n]: `i18n-alternate-${m.iso}`,
552
+ return f.iso && f.iso !== f.code && G.push({
553
+ [a]: `i18n-alternate-${f.iso}`,
550
554
  rel: "alternate",
551
- href: N,
552
- hreflang: m.iso
553
- }), V;
554
- });
555
- a.value.meta = [b, h, ...x], a.value.link = [$, ...O];
555
+ href: W,
556
+ hreflang: f.iso
557
+ }), G;
558
+ }), M = S(q, void 0);
559
+ let _ = null;
560
+ if (d && l && M) {
561
+ const f = l.getCurrentPath(), C = d(f, M), w = typeof C == "string" ? C : C?.path || "/";
562
+ if (w) {
563
+ let P;
564
+ w.startsWith("http://") || w.startsWith("https://") ? P = w : P = `${typeof c == "function" ? c() : c}${w.startsWith("/") ? "" : "/"}${w}`, _ = {
565
+ [a]: "i18n-xd",
566
+ rel: "alternate",
567
+ href: P,
568
+ hreflang: "x-default"
569
+ };
570
+ }
571
+ }
572
+ n.value.meta = [L, g, ...j], n.value.link = [O, ...N, ..._ ? [_] : []];
556
573
  }
557
574
  return {
558
- metaObject: a,
559
- updateMeta: d
575
+ metaObject: n,
576
+ updateMeta: h
560
577
  };
561
578
  }
562
- class ae extends J {
579
+ class oe extends X {
563
580
  constructor(e) {
564
- const n = {
581
+ const a = {
565
582
  translations: /* @__PURE__ */ new Map()
566
583
  };
567
584
  if (super({
568
- storage: n,
585
+ storage: a,
569
586
  plural: e.plural,
570
587
  missingWarn: e.missingWarn,
571
588
  missingHandler: e.missingHandler
572
- }), this.listeners = /* @__PURE__ */ new Set(), this.storage = n, this._locale = U(e.locale), this._fallbackLocale = U(e.fallbackLocale || e.locale), this._currentRoute = U("general"), this._revision = U(0), e.messages)
589
+ }), this.listeners = /* @__PURE__ */ new Set(), this.storage = a, this._locale = V(e.locale), this._fallbackLocale = V(e.fallbackLocale || e.locale), this._currentRoute = V("index"), this._revision = V(0), e.messages)
573
590
  for (const [r, c] of Object.entries(e.messages))
574
591
  this.helper.loadTranslations(r, c);
575
592
  }
@@ -600,17 +617,14 @@ class ae extends J {
600
617
  getRoute() {
601
618
  return this._currentRoute.value;
602
619
  }
603
- addTranslations(e, n, r = !0) {
604
- super.loadTranslationsCore(e, n, r), this._revision.value++, this.notifyListeners();
605
- }
606
- addRouteTranslations(e, n, r, c = !0) {
607
- super.loadRouteTranslationsCore(e, n, r, c), this._revision.value++, this.notifyListeners();
620
+ addTranslations(e, a, r = !0) {
621
+ super.loadTranslationsCore(e, a, r), this._revision.value++, this.notifyListeners();
608
622
  }
609
- mergeTranslations(e, n, r) {
610
- this.helper.mergeTranslation(e, n, r, !0), this._revision.value++, this.notifyListeners();
623
+ addRouteTranslations(e, a, r, c = !0) {
624
+ super.loadRouteTranslationsCore(e, a, r, c), this._revision.value++, this.notifyListeners();
611
625
  }
612
- mergeGlobalTranslations(e, n) {
613
- this.helper.mergeGlobalTranslation(e, n, !0), this._revision.value++, this.notifyListeners();
626
+ mergeTranslations(e, a, r) {
627
+ this.helper.mergeTranslation(e, a, r, !0), this._revision.value++, this.notifyListeners();
614
628
  }
615
629
  clearCache() {
616
630
  super.clearCache(), this._revision.value++, this.notifyListeners();
@@ -623,11 +637,11 @@ class ae extends J {
623
637
  }
624
638
  getAllTranslations() {
625
639
  const e = {};
626
- for (const [n, r] of this.storage.translations)
627
- if (!n.includes(":"))
628
- e[n] = r;
640
+ for (const [a, r] of this.storage.translations)
641
+ if (!a.includes(":"))
642
+ e[a] = r;
629
643
  else {
630
- const c = n.split(":")[0];
644
+ const c = a.split(":")[0];
631
645
  c && (e[c] || (e[c] = {}), Object.assign(e[c], r));
632
646
  }
633
647
  return e;
@@ -635,43 +649,37 @@ class ae extends J {
635
649
  getStorage() {
636
650
  return this.storage;
637
651
  }
638
- getGeneralCache() {
639
- const e = {};
640
- for (const [n, r] of this.storage.translations)
641
- n.includes(":") || (e[n] = r);
642
- return e;
643
- }
644
652
  getRouteCache() {
645
653
  const e = {};
646
- for (const [n, r] of this.storage.translations)
647
- n.includes(":") && (e[n] = r);
654
+ for (const [a, r] of this.storage.translations)
655
+ e[a] = r;
648
656
  return e;
649
657
  }
650
658
  }
651
- function se(t) {
652
- const { routingStrategy: e, locales: n, defaultLocale: r, ...c } = t, o = new ae(c);
653
- let u = null, f = e || null;
659
+ function fe(t) {
660
+ const { routingStrategy: e, locales: a, defaultLocale: r, ...c } = t, o = new oe(c);
661
+ let u = null, d = e || null;
654
662
  return {
655
663
  global: o,
656
- // Доступ к инстансу вне компонентов
657
- setRoutingStrategy: (a) => {
658
- f = a, u && u.provide(j, a);
664
+ // Access to instance outside components
665
+ setRoutingStrategy: (n) => {
666
+ d = n, u && u.provide(A, n);
659
667
  },
660
- // Метод для установки адаптера после создания
661
- install(a) {
662
- u = a, a.provide(D, o), f && a.provide(j, f), n && a.provide(K, n), r && a.provide(B, r), a.config.globalProperties.$t = (i, d, p, k) => o.t(i, d, p, k), a.config.globalProperties.$ts = (i, d, p, k) => o.ts(i, d, p, k), a.config.globalProperties.$tc = (i, d, p) => o.tc(i, d, p), a.config.globalProperties.$tn = (i, d) => o.tn(i, d), a.config.globalProperties.$td = (i, d) => o.td(i, d), a.config.globalProperties.$tdr = (i, d) => o.tdr(i, d), a.config.globalProperties.$has = (i, d) => o.has(i, d), a.config.globalProperties.$i18n = o, a.component("I18nT", te), a.component("I18nLink", Y), a.component("I18nGroup", X), a.component("I18nSwitcher", ee);
668
+ // Method for setting adapter after creation
669
+ install(n) {
670
+ u = n, n.provide(E, o), d && n.provide(A, d), a && n.provide(z, a), r && n.provide(q, 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", ae), n.component("I18nLink", te), n.component("I18nGroup", ee), n.component("I18nSwitcher", ne);
663
671
  }
664
672
  };
665
673
  }
666
- function ue(t, e, n) {
674
+ function de(t, e, a) {
667
675
  const r = e.map((o) => o.code), c = (o, u) => {
668
- const l = (typeof o == "string" ? o : o.path || "/").split("/").filter(Boolean), a = l[0];
669
- a !== void 0 && r.includes(a) && l.shift();
676
+ const l = (typeof o == "string" ? o : o.path || "/").split("/").filter(Boolean), n = l[0];
677
+ n !== void 0 && r.includes(n) && l.shift();
670
678
  const i = `/${l.join("/")}`;
671
- return u === n ? i : `/${u}${i === "/" ? "" : i}`;
679
+ return u === a ? i : `/${u}${i === "/" ? "" : i}`;
672
680
  };
673
681
  return {
674
- linkComponent: Q,
682
+ linkComponent: Y,
675
683
  getCurrentPath: () => t.currentRoute.value.path,
676
684
  push: (o) => {
677
685
  t.push(o.path).catch(() => {
@@ -689,19 +697,19 @@ function ue(t, e, n) {
689
697
  };
690
698
  }
691
699
  export {
692
- he as FormatService,
693
- B as I18nDefaultLocaleKey,
694
- X as I18nGroup,
695
- D as I18nInjectionKey,
696
- Y as I18nLink,
697
- K as I18nLocalesKey,
698
- ee as I18nSwitcher,
699
- te as I18nT,
700
- ae as VueI18n,
701
- se as createI18n,
702
- ue as createVueRouterAdapter,
703
- ge as defaultPlural,
704
- ye as interpolate,
705
- ne as useI18n,
706
- ce as useLocaleHead
700
+ ye as FormatService,
701
+ q as I18nDefaultLocaleKey,
702
+ ee as I18nGroup,
703
+ E as I18nInjectionKey,
704
+ te as I18nLink,
705
+ z as I18nLocalesKey,
706
+ ne as I18nSwitcher,
707
+ ae as I18nT,
708
+ oe as VueI18n,
709
+ fe as createI18n,
710
+ de as createVueRouterAdapter,
711
+ pe as defaultPlural,
712
+ me as interpolate,
713
+ re as useI18n,
714
+ ue as useLocaleHead
707
715
  };
@@ -36,6 +36,5 @@ export declare function useI18n(options?: UseI18nOptions): {
36
36
  addTranslations: (locale: string, translations: import('@i18n-micro/types').Translations, merge?: boolean) => void;
37
37
  addRouteTranslations: (locale: string, routeName: string, translations: import('@i18n-micro/types').Translations, merge?: boolean) => void;
38
38
  mergeTranslations: (locale: string, routeName: string, translations: import('@i18n-micro/types').Translations) => void;
39
- mergeGlobalTranslations: (locale: string, translations: import('@i18n-micro/types').Translations) => void;
40
39
  clearCache: () => void;
41
40
  };
@@ -1,5 +1,5 @@
1
1
  import { Params, CleanTranslation, TranslationKey } from '@i18n-micro/types';
2
- // Расширяем модуль '@vue/runtime-core', чтобы типы работали корректно во всех средах
2
+ // Extend '@vue/runtime-core' module so types work correctly in all environments
3
3
  declare module '@vue/runtime-core' {
4
4
  interface ComponentCustomProperties {
5
5
  $t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-micro/vue",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
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.1.2",
23
- "@i18n-micro/types": "1.1.1"
22
+ "@i18n-micro/core": "1.2.0",
23
+ "@i18n-micro/types": "1.1.6"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "vue": "^3.5.25",