@i18n-micro/vue 1.3.1 → 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 CHANGED
@@ -1 +1 @@
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;
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 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({
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,7 +15,7 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__PURE__ */ Symbol("i18n-local
15
15
  }
16
16
  },
17
17
  setup(t, { slots: e }) {
18
- const a = S(E);
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());
@@ -27,7 +27,7 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__PURE__ */ Symbol("i18n-local
27
27
  e.default?.({ prefix: t.prefix, t: r })
28
28
  );
29
29
  }
30
- }), te = F({
30
+ }), ae = B({
31
31
  name: "I18nLink",
32
32
  props: {
33
33
  to: {
@@ -44,10 +44,10 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__PURE__ */ Symbol("i18n-local
44
44
  }
45
45
  },
46
46
  setup(t, { slots: e }) {
47
- const a = S(E), r = S(A, void 0);
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 = $(() => typeof t.to == "string" ? /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to) : !1), o = $(() => {
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,12 +58,12 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__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
- }), d = $(() => u.value ? t.activeStyle : {});
66
+ }), d = C(() => u.value ? t.activeStyle : {});
67
67
  return () => c.value ? y(
68
68
  "a",
69
69
  {
@@ -92,7 +92,7 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__PURE__ */ Symbol("i18n-local
92
92
  e.default?.()
93
93
  );
94
94
  }
95
- }), ne = F({
95
+ }), re = B({
96
96
  name: "I18nSwitcher",
97
97
  props: {
98
98
  customLabels: {
@@ -153,38 +153,38 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__PURE__ */ Symbol("i18n-local
153
153
  }
154
154
  },
155
155
  setup(t, { slots: e }) {
156
- const a = S(E), r = S(A, void 0), c = S(z, void 0);
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 = $(() => 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) => {
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
- }, h = (s) => t.customLabels[s.code] || s.displayName || s.code, m = $(() => {
165
+ }, h = (s) => t.customLabels[s.code] || s.displayName || s.code, m = C(() => {
166
166
  const s = o.value.find((p) => p.code === u.value);
167
167
  return s ? h(s) : d.value || u.value;
168
168
  }), b = async (s) => {
169
- if (l.value = !1, await Q(), t.switchLocale) {
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 p = r.getCurrentPath(), L = t.localeRoute ? (() => {
175
+ const p = r.getCurrentPath(), v = t.localeRoute ? (() => {
176
176
  const g = t.localeRoute(p, s);
177
177
  return typeof g == "string" ? g : g.path || "/";
178
178
  })() : r?.resolvePath ? (() => {
179
179
  const g = r.resolvePath(p, s);
180
180
  return typeof g == "string" ? g : g.path || "/";
181
181
  })() : p;
182
- r.push({ path: L });
183
- }, R = {
182
+ r.push({ path: v });
183
+ }, S = {
184
184
  position: "relative",
185
185
  display: "inline-block",
186
186
  verticalAlign: "middle"
187
- }, x = {
187
+ }, R = {
188
188
  padding: "4px 12px",
189
189
  fontSize: "16px",
190
190
  cursor: "pointer",
@@ -194,7 +194,7 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__PURE__ */ Symbol("i18n-local
194
194
  display: "flex",
195
195
  alignItems: "center",
196
196
  justifyContent: "space-between"
197
- }, I = {
197
+ }, T = {
198
198
  position: "absolute",
199
199
  top: "100%",
200
200
  left: "0",
@@ -206,47 +206,47 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__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
- }, D = {
209
+ }, O = {
210
210
  margin: "0",
211
211
  padding: "0"
212
- }, k = {
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
- }, K = {
219
+ }, $ = {
220
220
  fontWeight: "bold",
221
221
  color: "#007bff"
222
- }, U = {
222
+ }, z = {
223
223
  marginLeft: "8px",
224
224
  display: "inline-block",
225
225
  transition: "transform 0.3s ease"
226
- }, H = {
226
+ }, V = {
227
227
  transform: "rotate(180deg)"
228
- }, v = (s) => s ? Array.isArray(s) ? s : [s] : [], T = (s) => {
228
+ }, L = (s) => s ? Array.isArray(s) ? s : [s] : [], x = (s) => {
229
229
  if (!l.value) return;
230
230
  const p = s.target;
231
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);
232
+ const v = n.value.contains(p), g = p.closest(".i18n-switcher-button") !== null;
233
+ !v && !g && (l.value = !1);
234
234
  };
235
- return Z(() => {
236
- document.addEventListener("click", T);
237
- }), J(() => {
238
- document.removeEventListener("click", T);
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(...v(e["before-button"]()));
241
+ e["before-button"] && s.push(...L(e["before-button"]()));
242
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(
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
244
  y(
245
245
  "span",
246
246
  {
247
247
  style: {
248
- ...U,
249
- ...l.value ? H : {},
248
+ ...z,
249
+ ...l.value ? V : {},
250
250
  ...t.customIconStyle
251
251
  }
252
252
  },
@@ -257,9 +257,9 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__PURE__ */ Symbol("i18n-local
257
257
  "button",
258
258
  {
259
259
  class: "i18n-switcher-button",
260
- style: { ...x, ...t.customButtonStyle },
261
- onClick: (L) => {
262
- L.preventDefault(), L.stopPropagation(), i(L);
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,
@@ -267,65 +267,65 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__PURE__ */ Symbol("i18n-local
267
267
  },
268
268
  p
269
269
  )
270
- ), e["before-dropdown"] && s.push(...v(e["before-dropdown"]())), l.value) {
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(
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
279
  y(
280
280
  "a",
281
281
  {
282
282
  class: `switcher-locale-${g.code}`,
283
- href: typeof _ == "string" ? _ : "#",
283
+ href: typeof D == "string" ? D : "#",
284
284
  style: {
285
- ...k,
286
- ...f ? K : {},
285
+ ...j,
286
+ ...U ? $ : {},
287
287
  ...t.customLinkStyle
288
288
  },
289
289
  // Prevent default navigation, use only handleSwitchLocale
290
- onClick: (C) => {
291
- C.preventDefault(), C.stopPropagation(), b(g.code);
290
+ onClick: (F) => {
291
+ F.preventDefault(), F.stopPropagation(), b(g.code);
292
292
  }
293
293
  },
294
- O
294
+ _
295
295
  )
296
- ), e["after-item"] && j.push(...v(e["after-item"]({ locale: g }))), L.push(
296
+ ), e["after-item"] && M.push(...L(e["after-item"]({ locale: g }))), v.push(
297
297
  y(
298
298
  "li",
299
299
  {
300
300
  key: g.code,
301
- style: { ...D, ...t.customItemStyle }
301
+ style: { ...O, ...t.customItemStyle }
302
302
  },
303
- j
303
+ M
304
304
  )
305
305
  );
306
- }), e["after-dropdown-items"] && L.push(...v(e["after-dropdown-items"]())), s.push(
306
+ }), e["after-dropdown-items"] && v.push(...L(e["after-dropdown-items"]())), s.push(
307
307
  y(
308
308
  "ul",
309
309
  {
310
310
  class: "i18n-switcher-dropdown",
311
- style: { ...I, ...t.customDropdownStyle }
311
+ style: { ...T, ...t.customDropdownStyle }
312
312
  },
313
- L
313
+ v
314
314
  )
315
315
  );
316
316
  }
317
- return e["after-dropdown"] && s.push(...v(e["after-dropdown"]())), y(
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: { ...R, ...t.customWrapperStyle }
322
+ style: { ...S, ...t.customWrapperStyle }
323
323
  },
324
324
  s
325
325
  );
326
326
  };
327
327
  }
328
- }), ae = F({
328
+ }), oe = B({
329
329
  name: "I18nT",
330
330
  props: {
331
331
  keypath: {
@@ -370,7 +370,7 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__PURE__ */ Symbol("i18n-local
370
370
  }
371
371
  },
372
372
  setup(t, { slots: e, attrs: a }) {
373
- const r = S(E);
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 () => {
@@ -421,8 +421,8 @@ const E = /* @__PURE__ */ Symbol("i18n"), z = /* @__PURE__ */ Symbol("i18n-local
421
421
  };
422
422
  }
423
423
  });
424
- function re(t) {
425
- const e = S(E), a = S(A, void 0), r = S(z, void 0), c = S(q, void 0);
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)
@@ -434,7 +434,7 @@ function re(t) {
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;
@@ -475,93 +475,97 @@ function re(t) {
475
475
  clearCache: e.clearCache.bind(e)
476
476
  };
477
477
  }
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({
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
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;
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
491
  function h(m = []) {
492
492
  if (!l) {
493
493
  n.value = { htmlAttrs: {}, link: [], meta: [] };
494
494
  return;
495
495
  }
496
- const b = o(), R = u(), x = R.find((f) => f.code === b);
497
- if (!x)
496
+ const b = o(), S = u(), R = S.find((f) => f.code === b);
497
+ if (!R)
498
498
  return;
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);
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
507
  const f = `/${b}`;
508
- T = `${s}${f}${v.startsWith("/") ? "" : "/"}${v}`;
508
+ s = `${p}${f}${x.startsWith("/") ? "" : "/"}${x}`;
509
509
  } else
510
- v = i(k, m), T = `${s}${v.startsWith("/") ? "" : "/"}${v}`;
510
+ x = i($, m), s = `${p}${x.startsWith("/") ? "" : "/"}${x}`;
511
511
  if (n.value = {
512
512
  htmlAttrs: {
513
- lang: I,
514
- ...e ? { dir: D } : {}
513
+ lang: T,
514
+ ...e ? { dir: j } : {}
515
515
  },
516
516
  link: [],
517
517
  meta: []
518
518
  }, !r)
519
519
  return;
520
- const p = R.filter((f) => !f.disabled), L = {
520
+ const v = S.filter((f) => !f.disabled && f.seo !== !1), g = {
521
521
  [a]: "i18n-og",
522
522
  property: "og:locale",
523
- content: I
524
- }, g = {
523
+ content: O
524
+ }, M = {
525
525
  [a]: "i18n-og-url",
526
526
  property: "og:url",
527
- content: T
528
- }, j = p.filter((f) => f.code !== b).map((f) => ({
529
- [a]: `i18n-og-alt-${f.iso || f.code}`,
530
- property: "og:locale:alternate",
531
- content: f.iso || f.code
532
- })), O = {
527
+ content: s
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 = {
533
536
  [a]: "i18n-can",
534
537
  rel: "canonical",
535
- href: T
536
- }, N = p.flatMap((f) => {
538
+ href: s
539
+ }, W = v.flatMap((f) => {
537
540
  if (!d || !l)
538
541
  return [];
539
- const C = l.getCurrentPath(), w = d(C, f.code), P = typeof w == "string" ? w : w?.path || "/";
542
+ const I = l.getCurrentPath(), w = d(I, f.code), P = typeof w == "string" ? w : w?.path || "/";
540
543
  if (!P)
541
544
  return [];
542
- let W;
543
- P.startsWith("http://") || P.startsWith("https://") ? W = P : W = `${typeof c == "function" ? c() : c}${P.startsWith("/") ? "" : "/"}${P}`;
544
- const G = [
545
+ let H;
546
+ P.startsWith("http://") || P.startsWith("https://") ? H = P : H = `${typeof c == "function" ? c() : c}${P.startsWith("/") ? "" : "/"}${P}`;
547
+ const J = [
545
548
  {
546
549
  [a]: `i18n-alternate-${f.code}`,
547
550
  rel: "alternate",
548
- href: W,
551
+ href: H,
549
552
  hreflang: f.code
550
553
  }
551
554
  ];
552
- return f.iso && f.iso !== f.code && G.push({
555
+ return f.iso && f.iso !== f.code && J.push({
553
556
  [a]: `i18n-alternate-${f.iso}`,
554
557
  rel: "alternate",
555
- href: W,
558
+ href: H,
556
559
  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 || "/";
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 || "/";
562
566
  if (w) {
563
567
  let P;
564
- w.startsWith("http://") || w.startsWith("https://") ? P = w : P = `${typeof c == "function" ? c() : c}${w.startsWith("/") ? "" : "/"}${w}`, _ = {
568
+ w.startsWith("http://") || w.startsWith("https://") ? P = w : P = `${typeof c == "function" ? c() : c}${w.startsWith("/") ? "" : "/"}${w}`, U = {
565
569
  [a]: "i18n-xd",
566
570
  rel: "alternate",
567
571
  href: P,
@@ -569,14 +573,14 @@ function ue(t = {}) {
569
573
  };
570
574
  }
571
575
  }
572
- n.value.meta = [L, g, ...j], n.value.link = [O, ...N, ..._ ? [_] : []];
576
+ n.value.meta = [g, M, ..._], n.value.link = [N, ...W, ...U ? [U] : []];
573
577
  }
574
578
  return {
575
579
  metaObject: n,
576
580
  updateMeta: h
577
581
  };
578
582
  }
579
- class oe extends X {
583
+ class ie extends ee {
580
584
  constructor(e) {
581
585
  const a = {
582
586
  translations: /* @__PURE__ */ new Map()
@@ -586,7 +590,7 @@ class oe extends X {
586
590
  plural: e.plural,
587
591
  missingWarn: e.missingWarn,
588
592
  missingHandler: e.missingHandler
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)
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)
590
594
  for (const [r, c] of Object.entries(e.messages))
591
595
  this.helper.loadTranslations(r, c);
592
596
  }
@@ -656,8 +660,8 @@ class oe extends X {
656
660
  return e;
657
661
  }
658
662
  }
659
- function fe(t) {
660
- const { routingStrategy: e, locales: a, defaultLocale: r, ...c } = t, o = new oe(c);
663
+ function he(t) {
664
+ const { routingStrategy: e, locales: a, defaultLocale: r, ...c } = t, o = new ie(c);
661
665
  let u = null, d = e || null;
662
666
  return {
663
667
  global: o,
@@ -667,11 +671,11 @@ function fe(t) {
667
671
  },
668
672
  // Method for setting adapter after creation
669
673
  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);
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);
671
675
  }
672
676
  };
673
677
  }
674
- function de(t, e, a) {
678
+ function ge(t, e, a) {
675
679
  const r = e.map((o) => o.code), c = (o, u) => {
676
680
  const l = (typeof o == "string" ? o : o.path || "/").split("/").filter(Boolean), n = l[0];
677
681
  n !== void 0 && r.includes(n) && l.shift();
@@ -679,7 +683,7 @@ function de(t, e, a) {
679
683
  return u === a ? i : `/${u}${i === "/" ? "" : i}`;
680
684
  };
681
685
  return {
682
- linkComponent: Y,
686
+ linkComponent: te,
683
687
  getCurrentPath: () => t.currentRoute.value.path,
684
688
  push: (o) => {
685
689
  t.push(o.path).catch(() => {
@@ -697,19 +701,19 @@ function de(t, e, a) {
697
701
  };
698
702
  }
699
703
  export {
700
- ye as FormatService,
701
- q as I18nDefaultLocaleKey,
702
- ee as I18nGroup,
704
+ me as FormatService,
705
+ Z as I18nDefaultLocaleKey,
706
+ ne as I18nGroup,
703
707
  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
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
715
719
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-micro/vue",
3
- "version": "1.3.1",
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.2.0",
23
- "@i18n-micro/types": "1.1.6"
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",