@i18n-micro/vue 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { PropType, CSSProperties } from 'vue';
1
+ import { CSSProperties, PropType } from 'vue';
2
2
  export declare const I18nLink: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
3
3
  to: {
4
4
  type: PropType<string | {
@@ -1,5 +1,5 @@
1
- import { PropType, CSSProperties, VNode } from 'vue';
2
1
  import { Locale } from '@i18n-micro/types';
2
+ import { CSSProperties, PropType, VNode } from 'vue';
3
3
  export declare const I18nSwitcher: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
4
4
  customLabels: {
5
5
  type: PropType<Record<string, string>>;
@@ -1,5 +1,5 @@
1
- import { PropType, VNode } from 'vue';
2
1
  import { PluralFunc, TranslationKey } from '@i18n-micro/types';
2
+ import { PropType, VNode } from 'vue';
3
3
  export declare const I18nT: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
4
4
  keypath: {
5
5
  type: PropType<TranslationKey>;
@@ -85,10 +85,10 @@ export declare const I18nT: import('vue').DefineComponent<import('vue').ExtractP
85
85
  type: PropType<Date | string | number>;
86
86
  };
87
87
  }>> & Readonly<{}>, {
88
+ html: boolean;
88
89
  tag: string;
89
90
  params: Record<string, string | number | boolean>;
90
91
  defaultValue: string;
91
- html: boolean;
92
92
  hideIfEmpty: boolean;
93
93
  customPluralRule: PluralFunc;
94
94
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
@@ -1,6 +1,6 @@
1
- import { Ref } from 'vue';
2
1
  import { BaseI18n, TranslationStorage } from '@i18n-micro/core';
3
- import { Translations, PluralFunc } from '@i18n-micro/types';
2
+ import { PluralFunc, Translations } from '@i18n-micro/types';
3
+ import { Ref } from 'vue';
4
4
  export interface VueI18nOptions {
5
5
  locale: string;
6
6
  fallbackLocale?: string;
@@ -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");class F 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}}const I=Symbol("i18n"),N=Symbol("i18n-locales"),U=Symbol("i18n-default-locale"),$=Symbol("i18n-router-strategy"),G=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());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)}}}),W=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?.())}}),q=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}))}}),B=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)}}});function J(t){const{routingStrategy:e,locales:n,defaultLocale:o,...u}=t,l=new F(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",G),a.component("I18nLink",W),a.component("I18nGroup",q),a.component("I18nSwitcher",B)}}}function z(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 Q(t={}){const{addDirAttribute:e=!0,identifierAttribute:n="id",addSeoAttributes:o=!0,baseUrl:u="/"}=t,{getLocale:l,getLocales:d,localeRoute:h}=z(),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}}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=q;exports.I18nInjectionKey=I;exports.I18nLink=W;exports.I18nLocalesKey=N;exports.I18nSwitcher=B;exports.I18nT=G;exports.VueI18n=F;exports.createI18n=J;exports.createVueRouterAdapter=X;exports.useI18n=z;exports.useLocaleHead=Q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("vue"),E=require("@i18n-micro/core"),Z=require("vue-router"),I=Symbol("i18n"),N=Symbol("i18n-locales"),U=Symbol("i18n-default-locale"),$=Symbol("i18n-router-strategy"),F=a.defineComponent({name:"I18nGroup",props:{prefix:{type:String,required:!0},groupClass:{type:String,default:""}},setup(t,{slots:e}){const r=a.inject(I);if(!r)throw new Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");const o=(u,l)=>r.t(`${t.prefix}.${u}`,l,void 0,r.getRoute());return()=>a.h("div",{class:["i18n-group",t.groupClass]},e.default?.({prefix:t.prefix,t:o}))}}),W=a.defineComponent({name:"I18nLink",props:{to:{type:[String,Object],required:!0},activeStyle:{type:Object,default:()=>({})},localeRoute:{type:Function,default:void 0}},setup(t,{slots:e}){const r=a.inject(I),o=a.inject($,void 0);if(!r)throw new Error("[i18n-micro] I18nLink: i18n instance not found. Make sure i18n plugin is installed.");const u=a.computed(()=>typeof t.to=="string"?/^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to):!1),l=a.computed(()=>{if(u.value)return t.to;if(t.localeRoute){const n=t.localeRoute(t.to);return typeof n=="string"?n:n.path||"/"}if(!o?.resolvePath)return typeof t.to=="string"?t.to:t.to.path||"/";const i=o.resolvePath(t.to,r.locale.value);return typeof i=="string"?i:i.path||"/"}),d=a.computed(()=>{if(u.value||!o)return!1;const i=o.getCurrentPath().replace(/\/$/,""),n=l.value.replace(/\/$/,"");return i===n}),h=a.computed(()=>d.value?t.activeStyle:{});return()=>u.value?a.h("a",{href:l.value,target:"_blank",rel:"noopener noreferrer",style:h.value},e.default?.()):o?.linkComponent?a.h(o.linkComponent,{to:l.value,style:h.value},{default:e.default}):a.h("a",{href:l.value,style:h.value,onClick:i=>{i.preventDefault(),o?o.push({path:l.value}):window.location.href=l.value}},e.default?.())}}),q=a.defineComponent({name:"I18nSwitcher",props:{customLabels:{type:Object,default:()=>({})},customWrapperStyle:{type:Object,default:()=>({})},customButtonStyle:{type:Object,default:()=>({})},customDropdownStyle:{type:Object,default:()=>({})},customItemStyle:{type:Object,default:()=>({})},customLinkStyle:{type:Object,default:()=>({})},customActiveLinkStyle:{type:Object,default:()=>({})},customDisabledLinkStyle:{type:Object,default:()=>({})},customIconStyle:{type:Object,default:()=>({})},locales:{type:Array,default:void 0},currentLocale:{type:[String,Function],default:void 0},getLocaleName:{type:Function,default:void 0},switchLocale:{type:Function,default:void 0},localeRoute:{type:Function,default:void 0}},setup(t,{slots:e}){const r=a.inject(I),o=a.inject($,void 0),u=a.inject(N,void 0);if(!r)throw new Error("[i18n-micro] I18nSwitcher: i18n instance not found. Make sure i18n plugin is installed.");if(!u&&!t.locales)throw new Error("[i18n-micro] I18nSwitcher: locales not provided. Make sure app.provide(I18nLocalesKey, locales) is called or pass locales prop.");const l=a.computed(()=>t.locales||u||[]),d=a.computed(()=>t.currentLocale!==void 0?typeof t.currentLocale=="function"?t.currentLocale():t.currentLocale:r.locale.value),h=a.computed(()=>t.getLocaleName?t.getLocaleName()||null:l.value.find(y=>y.code===r.locale.value)?.displayName||null),i=a.ref(!1),n=a.ref(null),c=s=>{s&&(s.stopPropagation(),s.preventDefault()),i.value=!i.value},f=s=>t.customLabels[s.code]||s.displayName||s.code,m=a.computed(()=>{const s=l.value.find(y=>y.code===d.value);return s?f(s):h.value||d.value}),k=async s=>{if(i.value=!1,await a.nextTick(),t.switchLocale){t.switchLocale(s);return}if(r.locale.value=s,!o)return;const y=o.getCurrentPath(),b=t.localeRoute?(()=>{const g=t.localeRoute(y,s);return typeof g=="string"?g:g.path||"/"})():o?.resolvePath?(()=>{const g=o.resolvePath(y,s);return typeof g=="string"?g:g.path||"/"})():y;o.push({path:b})},S={position:"relative",display:"inline-block",verticalAlign:"middle"},P={padding:"4px 12px",fontSize:"16px",cursor:"pointer",backgroundColor:"#fff",border:"1px solid #333",transition:"background-color 0.3s ease",display:"flex",alignItems:"center",justifyContent:"space-between"},R={position:"absolute",top:"100%",left:"0",zIndex:1e3,backgroundColor:"#fff",border:"1px solid #333",listStyle:"none",padding:"0",margin:"4px 0 0 0",minWidth:"150px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},j={margin:"0",padding:"0"},L={display:"block",padding:"8px 12px",color:"#333",textDecoration:"none",transition:"background-color 0.3s ease",cursor:"pointer"},K={fontWeight:"bold",color:"#007bff"},D={marginLeft:"8px",display:"inline-block",transition:"transform 0.3s ease"},M={transform:"rotate(180deg)"},v=s=>s?Array.isArray(s)?s:[s]:[],H=s=>{if(!i.value)return;const y=s.target;if(!y||!n.value)return;const b=n.value.contains(y),g=y.closest(".i18n-switcher-button")!==null;!b&&!g&&(i.value=!1)};return a.onMounted(()=>{document.addEventListener("click",H)}),a.onUnmounted(()=>{document.removeEventListener("click",H)}),()=>{const s=[];e["before-button"]&&s.push(...v(e["before-button"]()));const y=[];if(e["before-selected-locale"]&&y.push(...v(e["before-selected-locale"]())),y.push(a.h("span",m.value)),e["after-selected-locale"]&&y.push(...v(e["after-selected-locale"]())),y.push(a.h("span",{style:{...D,...i.value?M:{},...t.customIconStyle}},"▼")),s.push(a.h("button",{class:"i18n-switcher-button",style:{...P,...t.customButtonStyle},onClick:b=>{b.preventDefault(),b.stopPropagation(),c(b)},type:"button",ariaHaspopup:!0,ariaExpanded:i.value},y)),e["before-dropdown"]&&s.push(...v(e["before-dropdown"]())),i.value){const b=[];e["before-dropdown-items"]&&b.push(...v(e["before-dropdown-items"]())),l.value.forEach(g=>{const C=[];e["before-item"]&&C.push(...v(e["before-item"]({locale:g})));const T=[];e["before-link-content"]&&T.push(...v(e["before-link-content"]({locale:g}))),T.push(f(g)),e["after-link-content"]&&T.push(...v(e["after-link-content"]({locale:g})));const x=typeof window<"u"?window.location.pathname:"/",p=t.localeRoute?t.localeRoute(x,g.code):o?.resolvePath?o.resolvePath(x,g.code):x,_=typeof p=="string"?p:p.path||"#",O=g.code===d.value;C.push(a.h("a",{class:`switcher-locale-${g.code}`,href:typeof _=="string"?_:"#",style:{...L,...O?K:{},...t.customLinkStyle},onClick:w=>{w.preventDefault(),w.stopPropagation(),k(g.code)}},T)),e["after-item"]&&C.push(...v(e["after-item"]({locale:g}))),b.push(a.h("li",{key:g.code,style:{...j,...t.customItemStyle}},C))}),e["after-dropdown-items"]&&b.push(...v(e["after-dropdown-items"]())),s.push(a.h("ul",{class:"i18n-switcher-dropdown",style:{...R,...t.customDropdownStyle}},b))}return e["after-dropdown"]&&s.push(...v(e["after-dropdown"]())),a.h("div",{ref:n,class:"i18n-switcher-wrapper",style:{...S,...t.customWrapperStyle}},s)}}}),B=a.defineComponent({name:"I18nT",props:{keypath:{type:String,required:!0},plural:{type:[Number,String]},tag:{type:String,default:"span"},params:{type:Object,default:()=>({})},defaultValue:{type:String,default:""},html:{type:Boolean,default:!1},hideIfEmpty:{type:Boolean,default:!1},customPluralRule:{type:Function,default:null},number:{type:[Number,String]},date:{type:[Date,String,Number]},relativeDate:{type:[Date,String,Number]}},setup(t,{slots:e,attrs:r}){const o=a.inject(I);if(!o)throw new Error("[i18n-micro] I18nT: i18n instance not found. Make sure i18n plugin is installed.");return()=>{const u={},l=o.getRoute();if(t.number!==void 0){const n=Number(t.number),c=o.tn(n),f=o.t(t.keypath,{number:c,...t.params},void 0,l);return a.h(t.tag,{...r,innerHTML:f})}if(t.date!==void 0){const n=o.td(t.date),c=o.t(t.keypath,{date:n,...t.params},void 0,l);return a.h(t.tag,{...r,innerHTML:c})}if(t.relativeDate!==void 0){const n=o.tdr(t.relativeDate),c=o.t(t.keypath,{relativeDate:n,...t.params},void 0,l);return a.h(t.tag,{...r,innerHTML:c})}if(t.plural!==void 0){const n=Number.parseInt(t.plural.toString(),10);if(t.customPluralRule){const c=t.customPluralRule(t.keypath,n,t.params,o.locale.value,(f,m,k)=>o.t(f,m,k,l));return a.h(t.tag,{...r,innerHTML:c||""})}else{const c=o.tc(t.keypath,{count:n,...t.params});return a.h(t.tag,{...r,innerHTML:c})}}const d=(o.t(t.keypath,{...t.params,...u},void 0,l)??"").toString();if(t.hideIfEmpty&&!d.trim())return t.defaultValue??null;if(t.html)return a.h(t.tag,{...r,innerHTML:d});if(e.default)return a.h(t.tag,r,e.default({translation:d}));const h=[];let i=0;for(const[n,c]of Object.entries(e)){if(n==="default")continue;const f=`{${n}}`,m=d.indexOf(f,i);m!==-1&&(m>i&&h.push(d.slice(i,m)),c&&h.push(a.h(c)),i=m+f.length)}return i<d.length&&h.push(d.slice(i)),e.default?a.h(t.tag,r,e.default({children:h})):h.length>0?a.h(t.tag,r,h):a.h(t.tag,r,d)}}});function z(t){const e=a.inject(I),r=a.inject($,void 0),o=a.inject(N,void 0),u=a.inject(U,void 0);if(!e)throw new Error("[i18n-micro] useI18n() must be called after app.use(i18n). Make sure i18n plugin is installed.");if(!o)throw new Error("[i18n-micro] I18nLocalesKey not provided. Make sure app.provide(I18nLocalesKey, locales) is called.");if(!u)throw new Error("[i18n-micro] I18nDefaultLocaleKey not provided. Make sure app.provide(I18nDefaultLocaleKey, defaultLocale) is called.");const l=t?.locales||o,d=t?.defaultLocale||u,h=(i,n)=>r?.resolvePath?r.resolvePath(i,n||e.locale.value):i;return{instance:e,locale:a.computed({get:()=>e.locale.value,set:i=>{e.locale.value=i}}),getLocales:()=>l,defaultLocale:()=>d,getLocaleName:()=>l.find(n=>n.code===e.locale.value)?.displayName||null,localeRoute:h,localePath:(i,n)=>{const c=h(i,n);return typeof c=="string"?c:c.path||"/"},switchLocale:i=>{if(e.locale.value=i,r){const n=r.getCurrentPath(),c=h(n,i);r.push(typeof c=="string"?{path:c}:{path:c.path||"/"})}},t:e.t.bind(e),ts:e.ts.bind(e),tc:e.tc.bind(e),tn:e.tn.bind(e),td:e.td.bind(e),tdr:e.tdr.bind(e),has:e.has.bind(e),setRoute:e.setRoute.bind(e),getRoute:e.getRoute.bind(e),getLocale:()=>e.locale.value,addTranslations:e.addTranslations.bind(e),addRouteTranslations:e.addRouteTranslations.bind(e),mergeTranslations:e.mergeTranslations.bind(e),clearCache:e.clearCache.bind(e)}}function J(t={}){const{addDirAttribute:e=!0,identifierAttribute:r="id",addSeoAttributes:o=!0,baseUrl:u="/"}=t,{getLocale:l,getLocales:d,localeRoute:h}=z(),i=a.inject($,void 0),n=a.ref({htmlAttrs:{},link:[],meta:[]});function c(m,k){const S=new URL(m,"http://localhost"),P=new URLSearchParams(S.search),R={};for(const L of k)P.has(L)&&(R[L]=P.get(L));const j=new URLSearchParams(R);return j.toString()?`${S.pathname}?${j.toString()}`:S.pathname}function f(m=[]){if(!i){n.value={htmlAttrs:{},link:[],meta:[]};return}const k=l(),S=d(),P=S.find(p=>p.code===k);if(!P)return;const R=P.iso||k,j=P.dir||"auto";let L=i.getCurrentPath();L.startsWith("/")||(L=`/${L}`);const K=L.split("/").filter(Boolean),D=S.find(p=>K[0]===p.code);let M=L,v;D?(M=L.slice(D.code.length+1)||"/",v=c(M,m)):v=c(L,m);const s=`${typeof u=="function"?u():u}${v.startsWith("/")?"":"/"}${v}`;if(n.value={htmlAttrs:{lang:R,...e?{dir:j}:{}},link:[],meta:[]},!o)return;const y=S,b={[r]:"i18n-og",property:"og:locale",content:R},g={[r]:"i18n-og-url",property:"og:url",content:s},C=y.map(p=>({[r]:`i18n-og-alt-${p.iso||p.code}`,property:"og:locale:alternate",content:p.iso||p.code})),T={[r]:"i18n-can",rel:"canonical",href:s},x=y.flatMap(p=>{if(!h||!i)return[];const _=i.getCurrentPath(),O=h(_,p.code),w=typeof O=="string"?O:O?.path||"/";if(!w)return[];let A;w.startsWith("http://")||w.startsWith("https://")?A=w:A=`${typeof u=="function"?u():u}${w.startsWith("/")?"":"/"}${w}`;const V=[{[r]:`i18n-alternate-${p.code}`,rel:"alternate",href:A,hreflang:p.code}];return p.iso&&p.iso!==p.code&&V.push({[r]:`i18n-alternate-${p.iso}`,rel:"alternate",href:A,hreflang:p.iso}),V});n.value.meta=[b,g,...C],n.value.link=[T,...x]}return{metaObject:n,updateMeta:f}}class G extends E.BaseI18n{constructor(e){const r={translations:new Map};if(super({storage:r,plural:e.plural,missingWarn:e.missingWarn,missingHandler:e.missingHandler}),this.listeners=new Set,this.storage=r,this._locale=a.shallowRef(e.locale),this._fallbackLocale=a.shallowRef(e.fallbackLocale||e.locale),this._currentRoute=a.shallowRef("index"),this._revision=a.shallowRef(0),e.messages)for(const[o,u]of Object.entries(e.messages))this.helper.loadTranslations(o,u)}get locale(){return this._locale}set locale(e){typeof e=="string"?this._locale.value=e:this._locale=e}get fallbackLocale(){return this._fallbackLocale}set fallbackLocale(e){typeof e=="string"?this._fallbackLocale.value=e:this._fallbackLocale=e}get currentRoute(){return this._currentRoute}setRoute(e){this._currentRoute.value=e}getLocale(){return this._locale.value}getFallbackLocale(){return this._fallbackLocale.value}getRoute(){return this._currentRoute.value}addTranslations(e,r,o=!0){super.loadTranslationsCore(e,r,o),this._revision.value++,this.notifyListeners()}addRouteTranslations(e,r,o,u=!0){super.loadRouteTranslationsCore(e,r,o,u),this._revision.value++,this.notifyListeners()}mergeTranslations(e,r,o){this.helper.mergeTranslation(e,r,o,!0),this._revision.value++,this.notifyListeners()}clearCache(){super.clearCache(),this._revision.value++,this.notifyListeners()}subscribeToChanges(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notifyListeners(){this.listeners.forEach(e=>e())}getAllTranslations(){const e={};for(const[r,o]of this.storage.translations)if(!r.includes(":"))e[r]=o;else{const u=r.split(":")[0];u&&(e[u]||(e[u]={}),Object.assign(e[u],o))}return e}getStorage(){return this.storage}getRouteCache(){const e={};for(const[r,o]of this.storage.translations)e[r]=o;return e}}function Q(t){const{routingStrategy:e,locales:r,defaultLocale:o,...u}=t,l=new G(u);let d=null,h=e||null;return{global:l,setRoutingStrategy:n=>{h=n,d&&d.provide($,n)},install(n){d=n,n.provide(I,l),h&&n.provide($,h),r&&n.provide(N,r),o&&n.provide(U,o),n.config.globalProperties.$t=(c,f,m,k)=>l.t(c,f,m,k),n.config.globalProperties.$ts=(c,f,m,k)=>l.ts(c,f,m,k),n.config.globalProperties.$tc=(c,f,m)=>l.tc(c,f,m),n.config.globalProperties.$tn=(c,f)=>l.tn(c,f),n.config.globalProperties.$td=(c,f)=>l.td(c,f),n.config.globalProperties.$tdr=(c,f)=>l.tdr(c,f),n.config.globalProperties.$has=(c,f)=>l.has(c,f),n.config.globalProperties.$i18n=l,n.component("I18nT",B),n.component("I18nLink",W),n.component("I18nGroup",F),n.component("I18nSwitcher",q)}}}function X(t,e,r){const o=e.map(l=>l.code),u=(l,d)=>{const i=(typeof l=="string"?l:l.path||"/").split("/").filter(Boolean),n=i[0];n!==void 0&&o.includes(n)&&i.shift();const c=`/${i.join("/")}`;return d===r?c:`/${d}${c==="/"?"":c}`};return{linkComponent:Z.RouterLink,getCurrentPath:()=>t.currentRoute.value.path,push:l=>{t.push(l.path).catch(()=>{})},replace:l=>{t.replace(l.path).catch(()=>{})},resolvePath:(l,d)=>u(l,d),getRoute:()=>({fullPath:t.currentRoute.value.fullPath,query:t.currentRoute.value.query})}}Object.defineProperty(exports,"FormatService",{enumerable:!0,get:()=>E.FormatService});Object.defineProperty(exports,"defaultPlural",{enumerable:!0,get:()=>E.defaultPlural});Object.defineProperty(exports,"interpolate",{enumerable:!0,get:()=>E.interpolate});exports.I18nDefaultLocaleKey=U;exports.I18nGroup=F;exports.I18nInjectionKey=I;exports.I18nLink=W;exports.I18nLocalesKey=N;exports.I18nSwitcher=q;exports.I18nT=B;exports.VueI18n=G;exports.createI18n=Q;exports.createVueRouterAdapter=X;exports.useI18n=z;exports.useLocaleHead=J;
package/dist/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- export { createI18n } from './plugin';
2
- export type { I18nPlugin } from './plugin';
3
- export { useI18n, type UseI18nOptions } from './use-i18n';
4
- export { VueI18n, type VueI18nOptions } from './composer';
5
- export { I18nT } from './components/i18n-t';
6
- export { I18nLink } from './components/i18n-link';
7
1
  export { I18nGroup } from './components/i18n-group';
2
+ export { I18nLink } from './components/i18n-link';
8
3
  export { I18nSwitcher } from './components/i18n-switcher';
9
- export { I18nInjectionKey, I18nLocalesKey, I18nDefaultLocaleKey } from './injection';
10
- export { useLocaleHead } from './composables/use-locale-head';
4
+ export { I18nT } from './components/i18n-t';
11
5
  export type { UseLocaleHeadOptions } from './composables/use-locale-head';
12
- export type { I18nRoutingStrategy } from './router/types';
6
+ export { useLocaleHead } from './composables/use-locale-head';
7
+ export { VueI18n, type VueI18nOptions } from './composer';
8
+ export { I18nDefaultLocaleKey, I18nInjectionKey, I18nLocalesKey } from './injection';
9
+ export type { I18nPlugin } from './plugin';
10
+ export { createI18n } from './plugin';
11
+ export { type UseI18nOptions, useI18n } from './use-i18n';
12
+ export { defaultPlural, FormatService, interpolate } from '@i18n-micro/core';
13
+ export type { CleanTranslation, Getter, Locale, LocaleCode, Params, PluralFunc, Translations, } from '@i18n-micro/types';
13
14
  export { createVueRouterAdapter } from './router/adapter';
14
- export type { Translations, Params, PluralFunc, Getter, Locale, LocaleCode, CleanTranslation, } from '@i18n-micro/types';
15
- export { interpolate, FormatService, defaultPlural } from '@i18n-micro/core';
15
+ export type { I18nRoutingStrategy } from './router/types';
package/dist/index.mjs CHANGED
@@ -1,200 +1,33 @@
1
- import { shallowRef as U, defineComponent as H, inject as S, h as g, computed as R, ref as G, onMounted as z, onUnmounted as q, nextTick as Z } from "vue";
1
+ import { defineComponent as H, inject as S, h as g, computed as R, ref as K, onMounted as q, onUnmounted as G, nextTick as Z, shallowRef as U } from "vue";
2
2
  import { BaseI18n as J } from "@i18n-micro/core";
3
3
  import { FormatService as he, defaultPlural as ge, interpolate as ye } from "@i18n-micro/core";
4
4
  import { RouterLink as Q } from "vue-router";
5
- class X extends J {
6
- constructor(e) {
7
- const n = {
8
- translations: /* @__PURE__ */ new Map()
9
- };
10
- if (super({
11
- storage: n,
12
- plural: e.plural,
13
- missingWarn: e.missingWarn,
14
- missingHandler: e.missingHandler
15
- }), 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)
16
- for (const [r, c] of Object.entries(e.messages))
17
- this.helper.loadTranslations(r, c);
18
- }
19
- get locale() {
20
- return this._locale;
21
- }
22
- set locale(e) {
23
- typeof e == "string" ? this._locale.value = e : this._locale = e;
24
- }
25
- get fallbackLocale() {
26
- return this._fallbackLocale;
27
- }
28
- set fallbackLocale(e) {
29
- typeof e == "string" ? this._fallbackLocale.value = e : this._fallbackLocale = e;
30
- }
31
- get currentRoute() {
32
- return this._currentRoute;
33
- }
34
- setRoute(e) {
35
- this._currentRoute.value = e;
36
- }
37
- getLocale() {
38
- return this._locale.value;
39
- }
40
- getFallbackLocale() {
41
- return this._fallbackLocale.value;
42
- }
43
- getRoute() {
44
- return this._currentRoute.value;
45
- }
46
- addTranslations(e, n, r = !0) {
47
- super.loadTranslationsCore(e, n, r), this._revision.value++, this.notifyListeners();
48
- }
49
- addRouteTranslations(e, n, r, c = !0) {
50
- super.loadRouteTranslationsCore(e, n, r, c), this._revision.value++, this.notifyListeners();
51
- }
52
- mergeTranslations(e, n, r) {
53
- this.helper.mergeTranslation(e, n, r, !0), this._revision.value++, this.notifyListeners();
54
- }
55
- mergeGlobalTranslations(e, n) {
56
- this.helper.mergeGlobalTranslation(e, n, !0), this._revision.value++, this.notifyListeners();
57
- }
58
- clearCache() {
59
- super.clearCache(), this._revision.value++, this.notifyListeners();
60
- }
61
- subscribeToChanges(e) {
62
- return this.listeners.add(e), () => this.listeners.delete(e);
63
- }
64
- notifyListeners() {
65
- this.listeners.forEach((e) => e());
66
- }
67
- getAllTranslations() {
68
- const e = {};
69
- for (const [n, r] of this.storage.translations)
70
- if (!n.includes(":"))
71
- e[n] = r;
72
- else {
73
- const c = n.split(":")[0];
74
- c && (e[c] || (e[c] = {}), Object.assign(e[c], r));
75
- }
76
- return e;
77
- }
78
- getStorage() {
79
- return this.storage;
80
- }
81
- getGeneralCache() {
82
- const e = {};
83
- for (const [n, r] of this.storage.translations)
84
- n.includes(":") || (e[n] = r);
85
- return e;
86
- }
87
- getRouteCache() {
88
- const e = {};
89
- for (const [n, r] of this.storage.translations)
90
- n.includes(":") && (e[n] = r);
91
- return e;
92
- }
93
- }
94
- const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-locales"), B = /* @__PURE__ */ Symbol("i18n-default-locale"), j = /* @__PURE__ */ Symbol("i18n-router-strategy"), Y = H({
95
- name: "I18nT",
5
+ const D = /* @__PURE__ */ Symbol("i18n"), V = /* @__PURE__ */ Symbol("i18n-locales"), z = /* @__PURE__ */ Symbol("i18n-default-locale"), j = /* @__PURE__ */ Symbol("i18n-router-strategy"), X = H({
6
+ name: "I18nGroup",
96
7
  props: {
97
- keypath: {
8
+ prefix: {
98
9
  type: String,
99
10
  required: !0
100
11
  },
101
- plural: {
102
- type: [Number, String]
103
- },
104
- tag: {
105
- type: String,
106
- default: "span"
107
- },
108
- params: {
109
- type: Object,
110
- default: () => ({})
111
- },
112
- defaultValue: {
12
+ groupClass: {
113
13
  type: String,
114
14
  default: ""
115
- },
116
- html: {
117
- type: Boolean,
118
- default: !1
119
- },
120
- hideIfEmpty: {
121
- type: Boolean,
122
- default: !1
123
- },
124
- customPluralRule: {
125
- type: Function,
126
- default: null
127
- },
128
- number: {
129
- type: [Number, String]
130
- },
131
- date: {
132
- type: [Date, String, Number]
133
- },
134
- relativeDate: {
135
- type: [Date, String, Number]
136
15
  }
137
16
  },
138
- setup(t, { slots: e, attrs: n }) {
139
- const r = S(D);
140
- if (!r)
141
- throw new Error("[i18n-micro] I18nT: i18n instance not found. Make sure i18n plugin is installed.");
142
- return () => {
143
- const c = {}, o = r.getRoute();
144
- if (t.number !== void 0) {
145
- const a = Number(t.number), i = r.tn(a), d = r.t(t.keypath, { number: i, ...t.params }, void 0, o);
146
- return g(t.tag, { ...n, innerHTML: d });
147
- }
148
- if (t.date !== void 0) {
149
- const a = r.td(t.date), i = r.t(t.keypath, { date: a, ...t.params }, void 0, o);
150
- return g(t.tag, { ...n, innerHTML: i });
151
- }
152
- if (t.relativeDate !== void 0) {
153
- const a = r.tdr(t.relativeDate), i = r.t(t.keypath, { relativeDate: a, ...t.params }, void 0, o);
154
- return g(t.tag, { ...n, innerHTML: i });
155
- }
156
- if (t.plural !== void 0) {
157
- const a = Number.parseInt(t.plural.toString());
158
- if (t.customPluralRule) {
159
- const i = t.customPluralRule(
160
- t.keypath,
161
- a,
162
- t.params,
163
- r.locale.value,
164
- (d, p, k) => r.t(d, p, k, o)
165
- );
166
- return g(t.tag, { ...n, innerHTML: i || "" });
167
- } else {
168
- const i = r.tc(t.keypath, { count: a, ...t.params });
169
- return g(t.tag, { ...n, innerHTML: i });
170
- }
171
- }
172
- const u = (r.t(t.keypath, { ...t.params, ...c }, void 0, o) ?? "").toString();
173
- if (t.hideIfEmpty && !u.trim())
174
- return t.defaultValue ?? null;
175
- if (t.html)
176
- return g(t.tag, { ...n, innerHTML: u });
177
- if (e.default)
178
- return g(
179
- t.tag,
180
- n,
181
- e.default({ translation: u })
182
- );
183
- const f = [];
184
- let l = 0;
185
- for (const [a, i] of Object.entries(e)) {
186
- if (a === "default") continue;
187
- const d = `{${a}}`, p = u.indexOf(d, l);
188
- p !== -1 && (p > l && f.push(u.slice(l, p)), i && f.push(g(i)), l = p + d.length);
189
- }
190
- return l < u.length && f.push(u.slice(l)), e.default ? g(
191
- t.tag,
192
- n,
193
- e.default({ children: f })
194
- ) : f.length > 0 ? g(t.tag, n, f) : g(t.tag, n, u);
195
- };
17
+ setup(t, { slots: e }) {
18
+ const a = S(D);
19
+ if (!a)
20
+ throw new Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");
21
+ const r = (c, o) => a.t(`${t.prefix}.${c}`, o, void 0, a.getRoute());
22
+ return () => g(
23
+ "div",
24
+ {
25
+ class: ["i18n-group", t.groupClass]
26
+ },
27
+ e.default?.({ prefix: t.prefix, t: r })
28
+ );
196
29
  }
197
- }), ee = H({
30
+ }), Y = H({
198
31
  name: "I18nLink",
199
32
  props: {
200
33
  to: {
@@ -211,64 +44,55 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
211
44
  }
212
45
  },
213
46
  setup(t, { slots: e }) {
214
- const n = S(D), r = S(j, void 0);
215
- if (!n)
47
+ const a = S(D), r = S(j, void 0);
48
+ if (!a)
216
49
  throw new Error("[i18n-micro] I18nLink: i18n instance not found. Make sure i18n plugin is installed.");
217
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(() => {
218
51
  if (c.value)
219
52
  return t.to;
220
53
  if (t.localeRoute) {
221
- const a = t.localeRoute(t.to);
222
- return typeof a == "string" ? a : a.path || "/";
54
+ const n = t.localeRoute(t.to);
55
+ return typeof n == "string" ? n : n.path || "/";
223
56
  }
224
57
  if (!r?.resolvePath)
225
58
  return typeof t.to == "string" ? t.to : t.to.path || "/";
226
- const l = r.resolvePath(t.to, n.locale.value);
59
+ const l = r.resolvePath(t.to, a.locale.value);
227
60
  return typeof l == "string" ? l : l.path || "/";
228
61
  }), u = R(() => {
229
62
  if (c.value || !r)
230
63
  return !1;
231
- const l = r.getCurrentPath().replace(/\/$/, ""), a = o.value.replace(/\/$/, "");
232
- return l === a;
64
+ const l = r.getCurrentPath().replace(/\/$/, ""), n = o.value.replace(/\/$/, "");
65
+ return l === n;
233
66
  }), f = R(() => u.value ? t.activeStyle : {});
234
- return () => c.value ? g("a", {
235
- href: o.value,
236
- target: "_blank",
237
- rel: "noopener noreferrer",
238
- style: f.value
239
- }, e.default?.()) : r?.linkComponent ? g(r.linkComponent, {
240
- to: o.value,
241
- style: f.value
242
- }, { default: e.default }) : g("a", {
243
- href: o.value,
244
- style: f.value,
245
- onClick: (l) => {
246
- l.preventDefault(), r ? r.push({ path: o.value }) : window.location.href = o.value;
247
- }
248
- }, e.default?.());
249
- }
250
- }), te = H({
251
- name: "I18nGroup",
252
- props: {
253
- prefix: {
254
- type: String,
255
- required: !0
256
- },
257
- groupClass: {
258
- type: String,
259
- default: ""
260
- }
261
- },
262
- setup(t, { slots: e }) {
263
- const n = S(D);
264
- if (!n)
265
- throw new Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");
266
- const r = (c, o) => n.t(`${t.prefix}.${c}`, o, void 0, n.getRoute());
267
- return () => g("div", {
268
- class: ["i18n-group", t.groupClass]
269
- }, e.default?.({ prefix: t.prefix, t: r }));
67
+ return () => c.value ? g(
68
+ "a",
69
+ {
70
+ href: o.value,
71
+ target: "_blank",
72
+ rel: "noopener noreferrer",
73
+ style: f.value
74
+ },
75
+ e.default?.()
76
+ ) : r?.linkComponent ? g(
77
+ r.linkComponent,
78
+ {
79
+ to: o.value,
80
+ style: f.value
81
+ },
82
+ { default: e.default }
83
+ ) : g(
84
+ "a",
85
+ {
86
+ href: o.value,
87
+ style: f.value,
88
+ onClick: (l) => {
89
+ l.preventDefault(), r ? r.push({ path: o.value }) : window.location.href = o.value;
90
+ }
91
+ },
92
+ e.default?.()
93
+ );
270
94
  }
271
- }), ne = H({
95
+ }), ee = H({
272
96
  name: "I18nSwitcher",
273
97
  props: {
274
98
  customLabels: {
@@ -329,12 +153,14 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
329
153
  }
330
154
  },
331
155
  setup(t, { slots: e }) {
332
- const n = S(D), r = S(j, void 0), c = S(K, void 0);
333
- if (!n)
156
+ const a = S(D), r = S(j, void 0), c = S(V, void 0);
157
+ if (!a)
334
158
  throw new Error("[i18n-micro] I18nSwitcher: i18n instance not found. Make sure i18n plugin is installed.");
335
159
  if (!c && !t.locales)
336
- throw new Error("[i18n-micro] I18nSwitcher: locales not provided. Make sure app.provide(I18nLocalesKey, locales) is called or pass locales prop.");
337
- 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) => {
160
+ throw new Error(
161
+ "[i18n-micro] I18nSwitcher: locales not provided. Make sure app.provide(I18nLocalesKey, locales) is called or pass locales prop."
162
+ );
163
+ const o = R(() => t.locales || c || []), u = R(() => t.currentLocale !== void 0 ? typeof t.currentLocale == "function" ? t.currentLocale() : t.currentLocale : a.locale.value), f = R(() => t.getLocaleName ? t.getLocaleName() || null : o.value.find((y) => y.code === a.locale.value)?.displayName || null), l = K(!1), n = K(null), i = (s) => {
338
164
  s && (s.stopPropagation(), s.preventDefault()), l.value = !l.value;
339
165
  }, d = (s) => t.customLabels[s.code] || s.displayName || s.code, p = R(() => {
340
166
  const s = o.value.find((y) => y.code === u.value);
@@ -344,7 +170,7 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
344
170
  t.switchLocale(s);
345
171
  return;
346
172
  }
347
- if (n.locale.value = s, !r)
173
+ if (a.locale.value = s, !r)
348
174
  return;
349
175
  const y = r.getCurrentPath(), b = t.localeRoute ? (() => {
350
176
  const h = t.localeRoute(y, s);
@@ -358,7 +184,7 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
358
184
  position: "relative",
359
185
  display: "inline-block",
360
186
  verticalAlign: "middle"
361
- }, C = {
187
+ }, I = {
362
188
  padding: "4px 12px",
363
189
  fontSize: "16px",
364
190
  cursor: "pointer",
@@ -368,7 +194,7 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
368
194
  display: "flex",
369
195
  alignItems: "center",
370
196
  justifyContent: "space-between"
371
- }, I = {
197
+ }, C = {
372
198
  position: "absolute",
373
199
  top: "100%",
374
200
  left: "0",
@@ -380,7 +206,7 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
380
206
  margin: "4px 0 0 0",
381
207
  minWidth: "150px",
382
208
  boxShadow: "0 2px 8px rgba(0,0,0,0.15)"
383
- }, T = {
209
+ }, x = {
384
210
  margin: "0",
385
211
  padding: "0"
386
212
  }, L = {
@@ -402,104 +228,208 @@ const D = /* @__PURE__ */ Symbol("i18n"), K = /* @__PURE__ */ Symbol("i18n-local
402
228
  }, v = (s) => s ? Array.isArray(s) ? s : [s] : [], F = (s) => {
403
229
  if (!l.value) return;
404
230
  const y = s.target;
405
- if (!y || !a.value) return;
406
- const b = a.value.contains(y), h = y.closest(".i18n-switcher-button") !== null;
231
+ if (!y || !n.value) return;
232
+ const b = n.value.contains(y), h = y.closest(".i18n-switcher-button") !== null;
407
233
  !b && !h && (l.value = !1);
408
234
  };
409
- return z(() => {
235
+ return q(() => {
410
236
  document.addEventListener("click", F);
411
- }), q(() => {
237
+ }), G(() => {
412
238
  document.removeEventListener("click", F);
413
239
  }), () => {
414
240
  const s = [];
415
241
  e["before-button"] && s.push(...v(e["before-button"]()));
416
242
  const y = [];
417
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(
418
- g("span", {
419
- style: {
420
- ..._,
421
- ...l.value ? A : {},
422
- ...t.customIconStyle
423
- }
424
- }, "▼")
244
+ g(
245
+ "span",
246
+ {
247
+ style: {
248
+ ..._,
249
+ ...l.value ? A : {},
250
+ ...t.customIconStyle
251
+ }
252
+ },
253
+ "▼"
254
+ )
425
255
  ), s.push(
426
- g("button", {
427
- class: "i18n-switcher-button",
428
- style: { ...C, ...t.customButtonStyle },
429
- onClick: (b) => {
430
- b.preventDefault(), b.stopPropagation(), i(b);
256
+ g(
257
+ "button",
258
+ {
259
+ class: "i18n-switcher-button",
260
+ style: { ...I, ...t.customButtonStyle },
261
+ onClick: (b) => {
262
+ b.preventDefault(), b.stopPropagation(), i(b);
263
+ },
264
+ type: "button",
265
+ ariaHaspopup: !0,
266
+ ariaExpanded: l.value
431
267
  },
432
- type: "button",
433
- ariaHaspopup: !0,
434
- ariaExpanded: l.value
435
- }, y)
268
+ y
269
+ )
436
270
  ), e["before-dropdown"] && s.push(...v(e["before-dropdown"]())), l.value) {
437
271
  const b = [];
438
272
  e["before-dropdown-items"] && b.push(...v(e["before-dropdown-items"]())), o.value.forEach((h) => {
439
- const x = [];
440
- e["before-item"] && x.push(...v(e["before-item"]({ locale: h })));
441
273
  const $ = [];
442
- 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 })));
274
+ e["before-item"] && $.push(...v(e["before-item"]({ locale: h })));
275
+ const T = [];
276
+ e["before-link-content"] && T.push(...v(e["before-link-content"]({ locale: h }))), T.push(d(h)), e["after-link-content"] && T.push(...v(e["after-link-content"]({ locale: h })));
443
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;
444
- x.push(
445
- g("a", {
446
- class: `switcher-locale-${h.code}`,
447
- href: typeof E == "string" ? E : "#",
448
- style: {
449
- ...L,
450
- ...M ? W : {},
451
- ...t.customLinkStyle
278
+ $.push(
279
+ g(
280
+ "a",
281
+ {
282
+ class: `switcher-locale-${h.code}`,
283
+ href: typeof E == "string" ? E : "#",
284
+ style: {
285
+ ...L,
286
+ ...M ? W : {},
287
+ ...t.customLinkStyle
288
+ },
289
+ // Prevent default navigation, use only handleSwitchLocale
290
+ onClick: (P) => {
291
+ P.preventDefault(), P.stopPropagation(), k(h.code);
292
+ }
452
293
  },
453
- // Предотвращаем стандартную навигацию, используем только handleSwitchLocale
454
- onClick: (P) => {
455
- P.preventDefault(), P.stopPropagation(), k(h.code);
456
- }
457
- }, $)
458
- ), e["after-item"] && x.push(...v(e["after-item"]({ locale: h }))), b.push(
459
- g("li", {
460
- key: h.code,
461
- style: { ...T, ...t.customItemStyle }
462
- }, x)
294
+ T
295
+ )
296
+ ), e["after-item"] && $.push(...v(e["after-item"]({ locale: h }))), b.push(
297
+ g(
298
+ "li",
299
+ {
300
+ key: h.code,
301
+ style: { ...x, ...t.customItemStyle }
302
+ },
303
+ $
304
+ )
463
305
  );
464
306
  }), e["after-dropdown-items"] && b.push(...v(e["after-dropdown-items"]())), s.push(
465
- g("ul", {
466
- class: "i18n-switcher-dropdown",
467
- style: { ...I, ...t.customDropdownStyle }
468
- }, b)
307
+ g(
308
+ "ul",
309
+ {
310
+ class: "i18n-switcher-dropdown",
311
+ style: { ...C, ...t.customDropdownStyle }
312
+ },
313
+ b
314
+ )
469
315
  );
470
316
  }
471
- return e["after-dropdown"] && s.push(...v(e["after-dropdown"]())), g("div", {
472
- ref: a,
473
- class: "i18n-switcher-wrapper",
474
- style: { ...w, ...t.customWrapperStyle }
475
- }, s);
317
+ return e["after-dropdown"] && s.push(...v(e["after-dropdown"]())), g(
318
+ "div",
319
+ {
320
+ ref: n,
321
+ class: "i18n-switcher-wrapper",
322
+ style: { ...w, ...t.customWrapperStyle }
323
+ },
324
+ s
325
+ );
476
326
  };
477
327
  }
478
- });
479
- function ce(t) {
480
- const { routingStrategy: e, locales: n, defaultLocale: r, ...c } = t, o = new X(c);
481
- let u = null, f = e || null;
482
- return {
483
- global: o,
484
- // Доступ к инстансу вне компонентов
485
- setRoutingStrategy: (a) => {
486
- f = a, u && u.provide(j, a);
328
+ }), te = H({
329
+ name: "I18nT",
330
+ props: {
331
+ keypath: {
332
+ type: String,
333
+ required: !0
334
+ },
335
+ plural: {
336
+ type: [Number, String]
337
+ },
338
+ tag: {
339
+ type: String,
340
+ default: "span"
341
+ },
342
+ params: {
343
+ type: Object,
344
+ default: () => ({})
345
+ },
346
+ defaultValue: {
347
+ type: String,
348
+ default: ""
349
+ },
350
+ html: {
351
+ type: Boolean,
352
+ default: !1
353
+ },
354
+ hideIfEmpty: {
355
+ type: Boolean,
356
+ default: !1
357
+ },
358
+ customPluralRule: {
359
+ type: Function,
360
+ default: null
361
+ },
362
+ number: {
363
+ type: [Number, String]
487
364
  },
488
- // Метод для установки адаптера после создания
489
- install(a) {
490
- 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", Y), a.component("I18nLink", ee), a.component("I18nGroup", te), a.component("I18nSwitcher", ne);
365
+ date: {
366
+ type: [Date, String, Number]
367
+ },
368
+ relativeDate: {
369
+ type: [Date, String, Number]
491
370
  }
492
- };
493
- }
494
- function ae(t) {
495
- const e = S(D), n = S(j, void 0), r = S(K, void 0), c = S(B, void 0);
371
+ },
372
+ setup(t, { slots: e, attrs: a }) {
373
+ const r = S(D);
374
+ if (!r)
375
+ throw new Error("[i18n-micro] I18nT: i18n instance not found. Make sure i18n plugin is installed.");
376
+ return () => {
377
+ const c = {}, o = r.getRoute();
378
+ if (t.number !== void 0) {
379
+ const n = Number(t.number), i = r.tn(n), d = r.t(t.keypath, { number: i, ...t.params }, void 0, o);
380
+ return g(t.tag, { ...a, innerHTML: d });
381
+ }
382
+ if (t.date !== void 0) {
383
+ const n = r.td(t.date), i = r.t(t.keypath, { date: n, ...t.params }, void 0, o);
384
+ return g(t.tag, { ...a, innerHTML: i });
385
+ }
386
+ if (t.relativeDate !== void 0) {
387
+ const n = r.tdr(t.relativeDate), i = r.t(t.keypath, { relativeDate: n, ...t.params }, void 0, o);
388
+ return g(t.tag, { ...a, innerHTML: i });
389
+ }
390
+ if (t.plural !== void 0) {
391
+ const n = Number.parseInt(t.plural.toString(), 10);
392
+ if (t.customPluralRule) {
393
+ const i = t.customPluralRule(
394
+ t.keypath,
395
+ n,
396
+ t.params,
397
+ r.locale.value,
398
+ (d, p, k) => r.t(d, p, k, o)
399
+ );
400
+ return g(t.tag, { ...a, innerHTML: i || "" });
401
+ } else {
402
+ const i = r.tc(t.keypath, { count: n, ...t.params });
403
+ return g(t.tag, { ...a, innerHTML: i });
404
+ }
405
+ }
406
+ const u = (r.t(t.keypath, { ...t.params, ...c }, void 0, o) ?? "").toString();
407
+ if (t.hideIfEmpty && !u.trim())
408
+ return t.defaultValue ?? null;
409
+ if (t.html)
410
+ return g(t.tag, { ...a, innerHTML: u });
411
+ if (e.default)
412
+ return g(t.tag, a, e.default({ translation: u }));
413
+ const f = [];
414
+ let l = 0;
415
+ for (const [n, i] of Object.entries(e)) {
416
+ if (n === "default") continue;
417
+ const d = `{${n}}`, 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);
419
+ }
420
+ return l < u.length && f.push(u.slice(l)), e.default ? g(t.tag, a, e.default({ children: f })) : f.length > 0 ? g(t.tag, a, f) : g(t.tag, a, u);
421
+ };
422
+ }
423
+ });
424
+ function ne(t) {
425
+ const e = S(D), a = S(j, void 0), r = S(V, void 0), c = S(z, void 0);
496
426
  if (!e)
497
427
  throw new Error("[i18n-micro] useI18n() must be called after app.use(i18n). Make sure i18n plugin is installed.");
498
428
  if (!r)
499
429
  throw new Error("[i18n-micro] I18nLocalesKey not provided. Make sure app.provide(I18nLocalesKey, locales) is called.");
500
430
  if (!c)
501
431
  throw new Error("[i18n-micro] I18nDefaultLocaleKey not provided. Make sure app.provide(I18nDefaultLocaleKey, defaultLocale) is called.");
502
- 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, f = (l, n) => a?.resolvePath ? a.resolvePath(l, n || e.locale.value) : l;
503
433
  return {
504
434
  // Direct access to instance
505
435
  instance: e,
@@ -513,17 +443,17 @@ function ae(t) {
513
443
  // Locale helpers
514
444
  getLocales: () => o,
515
445
  defaultLocale: () => u,
516
- getLocaleName: () => o.find((a) => a.code === e.locale.value)?.displayName || null,
446
+ getLocaleName: () => o.find((n) => n.code === e.locale.value)?.displayName || null,
517
447
  // Routing helpers
518
448
  localeRoute: f,
519
- localePath: (l, a) => {
520
- const i = f(l, a);
449
+ localePath: (l, n) => {
450
+ const i = f(l, n);
521
451
  return typeof i == "string" ? i : i.path || "/";
522
452
  },
523
453
  switchLocale: (l) => {
524
- if (e.locale.value = l, n) {
525
- const a = n.getCurrentPath(), i = f(a, l);
526
- n.push(typeof i == "string" ? { path: i } : { path: i.path || "/" });
454
+ if (e.locale.value = l, a) {
455
+ const n = a.getCurrentPath(), i = f(n, l);
456
+ a.push(typeof i == "string" ? { path: i } : { path: i.path || "/" });
527
457
  }
528
458
  },
529
459
  // Translation methods (delegate to instance)
@@ -542,66 +472,60 @@ function ae(t) {
542
472
  addTranslations: e.addTranslations.bind(e),
543
473
  addRouteTranslations: e.addRouteTranslations.bind(e),
544
474
  mergeTranslations: e.mergeTranslations.bind(e),
545
- mergeGlobalTranslations: e.mergeGlobalTranslations.bind(e),
546
475
  clearCache: e.clearCache.bind(e)
547
476
  };
548
477
  }
549
- function se(t = {}) {
550
- const {
551
- addDirAttribute: e = !0,
552
- identifierAttribute: n = "id",
553
- addSeoAttributes: r = !0,
554
- baseUrl: c = "/"
555
- } = t, { getLocale: o, getLocales: u, localeRoute: f } = ae(), l = S(j, void 0), a = G({
478
+ function ce(t = {}) {
479
+ const { addDirAttribute: e = !0, identifierAttribute: a = "id", addSeoAttributes: r = !0, baseUrl: c = "/" } = t, { getLocale: o, getLocales: u, localeRoute: f } = ne(), l = S(j, void 0), n = K({
556
480
  htmlAttrs: {},
557
481
  link: [],
558
482
  meta: []
559
483
  });
560
484
  function i(p, k) {
561
- const w = new URL(p, "http://localhost"), C = new URLSearchParams(w.search), I = {};
485
+ const w = new URL(p, "http://localhost"), I = new URLSearchParams(w.search), C = {};
562
486
  for (const L of k)
563
- C.has(L) && (I[L] = C.get(L));
564
- const T = new URLSearchParams(I);
565
- return T.toString() ? `${w.pathname}?${T.toString()}` : w.pathname;
487
+ I.has(L) && (C[L] = I.get(L));
488
+ const x = new URLSearchParams(C);
489
+ return x.toString() ? `${w.pathname}?${x.toString()}` : w.pathname;
566
490
  }
567
491
  function d(p = []) {
568
492
  if (!l) {
569
- a.value = { htmlAttrs: {}, link: [], meta: [] };
493
+ n.value = { htmlAttrs: {}, link: [], meta: [] };
570
494
  return;
571
495
  }
572
- const k = o(), w = u(), C = w.find((m) => m.code === k);
573
- if (!C)
496
+ const k = o(), w = u(), I = w.find((m) => m.code === k);
497
+ if (!I)
574
498
  return;
575
- const I = C.iso || k, T = C.dir || "auto";
499
+ const C = I.iso || k, x = I.dir || "auto";
576
500
  let L = l.getCurrentPath();
577
501
  L.startsWith("/") || (L = `/${L}`);
578
502
  const W = L.split("/").filter(Boolean), _ = w.find((m) => W[0] === m.code);
579
503
  let A = L, v;
580
504
  _ ? (A = L.slice(_.code.length + 1) || "/", v = i(A, p)) : v = i(L, p);
581
505
  const s = `${typeof c == "function" ? c() : c}${v.startsWith("/") ? "" : "/"}${v}`;
582
- if (a.value = {
506
+ if (n.value = {
583
507
  htmlAttrs: {
584
- lang: I,
585
- ...e ? { dir: T } : {}
508
+ lang: C,
509
+ ...e ? { dir: x } : {}
586
510
  },
587
511
  link: [],
588
512
  meta: []
589
513
  }, !r)
590
514
  return;
591
515
  const y = w, b = {
592
- [n]: "i18n-og",
516
+ [a]: "i18n-og",
593
517
  property: "og:locale",
594
- content: I
518
+ content: C
595
519
  }, h = {
596
- [n]: "i18n-og-url",
520
+ [a]: "i18n-og-url",
597
521
  property: "og:url",
598
522
  content: s
599
- }, x = y.map((m) => ({
600
- [n]: `i18n-og-alt-${m.iso || m.code}`,
523
+ }, $ = y.map((m) => ({
524
+ [a]: `i18n-og-alt-${m.iso || m.code}`,
601
525
  property: "og:locale:alternate",
602
526
  content: m.iso || m.code
603
- })), $ = {
604
- [n]: "i18n-can",
527
+ })), T = {
528
+ [a]: "i18n-can",
605
529
  rel: "canonical",
606
530
  href: s
607
531
  }, O = y.flatMap((m) => {
@@ -612,32 +536,129 @@ function se(t = {}) {
612
536
  return [];
613
537
  let N;
614
538
  P.startsWith("http://") || P.startsWith("https://") ? N = P : N = `${typeof c == "function" ? c() : c}${P.startsWith("/") ? "" : "/"}${P}`;
615
- const V = [{
616
- [n]: `i18n-alternate-${m.code}`,
617
- rel: "alternate",
618
- href: N,
619
- hreflang: m.code
620
- }];
621
- return m.iso && m.iso !== m.code && V.push({
622
- [n]: `i18n-alternate-${m.iso}`,
539
+ const B = [
540
+ {
541
+ [a]: `i18n-alternate-${m.code}`,
542
+ rel: "alternate",
543
+ href: N,
544
+ hreflang: m.code
545
+ }
546
+ ];
547
+ return m.iso && m.iso !== m.code && B.push({
548
+ [a]: `i18n-alternate-${m.iso}`,
623
549
  rel: "alternate",
624
550
  href: N,
625
551
  hreflang: m.iso
626
- }), V;
552
+ }), B;
627
553
  });
628
- a.value.meta = [b, h, ...x], a.value.link = [$, ...O];
554
+ n.value.meta = [b, h, ...$], n.value.link = [T, ...O];
629
555
  }
630
556
  return {
631
- metaObject: a,
557
+ metaObject: n,
632
558
  updateMeta: d
633
559
  };
634
560
  }
635
- function ue(t, e, n) {
561
+ class ae extends J {
562
+ constructor(e) {
563
+ const a = {
564
+ translations: /* @__PURE__ */ new Map()
565
+ };
566
+ if (super({
567
+ storage: a,
568
+ plural: e.plural,
569
+ missingWarn: e.missingWarn,
570
+ missingHandler: e.missingHandler
571
+ }), this.listeners = /* @__PURE__ */ new Set(), this.storage = a, this._locale = U(e.locale), this._fallbackLocale = U(e.fallbackLocale || e.locale), this._currentRoute = U("index"), this._revision = U(0), e.messages)
572
+ for (const [r, c] of Object.entries(e.messages))
573
+ this.helper.loadTranslations(r, c);
574
+ }
575
+ get locale() {
576
+ return this._locale;
577
+ }
578
+ set locale(e) {
579
+ typeof e == "string" ? this._locale.value = e : this._locale = e;
580
+ }
581
+ get fallbackLocale() {
582
+ return this._fallbackLocale;
583
+ }
584
+ set fallbackLocale(e) {
585
+ typeof e == "string" ? this._fallbackLocale.value = e : this._fallbackLocale = e;
586
+ }
587
+ get currentRoute() {
588
+ return this._currentRoute;
589
+ }
590
+ setRoute(e) {
591
+ this._currentRoute.value = e;
592
+ }
593
+ getLocale() {
594
+ return this._locale.value;
595
+ }
596
+ getFallbackLocale() {
597
+ return this._fallbackLocale.value;
598
+ }
599
+ getRoute() {
600
+ return this._currentRoute.value;
601
+ }
602
+ addTranslations(e, a, r = !0) {
603
+ super.loadTranslationsCore(e, a, r), this._revision.value++, this.notifyListeners();
604
+ }
605
+ addRouteTranslations(e, a, r, c = !0) {
606
+ super.loadRouteTranslationsCore(e, a, r, c), this._revision.value++, this.notifyListeners();
607
+ }
608
+ mergeTranslations(e, a, r) {
609
+ this.helper.mergeTranslation(e, a, r, !0), this._revision.value++, this.notifyListeners();
610
+ }
611
+ clearCache() {
612
+ super.clearCache(), this._revision.value++, this.notifyListeners();
613
+ }
614
+ subscribeToChanges(e) {
615
+ return this.listeners.add(e), () => this.listeners.delete(e);
616
+ }
617
+ notifyListeners() {
618
+ this.listeners.forEach((e) => e());
619
+ }
620
+ getAllTranslations() {
621
+ const e = {};
622
+ for (const [a, r] of this.storage.translations)
623
+ if (!a.includes(":"))
624
+ e[a] = r;
625
+ else {
626
+ const c = a.split(":")[0];
627
+ c && (e[c] || (e[c] = {}), Object.assign(e[c], r));
628
+ }
629
+ return e;
630
+ }
631
+ getStorage() {
632
+ return this.storage;
633
+ }
634
+ getRouteCache() {
635
+ const e = {};
636
+ for (const [a, r] of this.storage.translations)
637
+ e[a] = r;
638
+ return e;
639
+ }
640
+ }
641
+ function se(t) {
642
+ const { routingStrategy: e, locales: a, defaultLocale: r, ...c } = t, o = new ae(c);
643
+ let u = null, f = e || null;
644
+ return {
645
+ global: o,
646
+ // Access to instance outside components
647
+ setRoutingStrategy: (n) => {
648
+ f = n, u && u.provide(j, n);
649
+ },
650
+ // Method for setting adapter after creation
651
+ install(n) {
652
+ u = n, n.provide(D, o), f && n.provide(j, f), a && n.provide(V, a), r && n.provide(z, r), n.config.globalProperties.$t = (i, d, p, k) => o.t(i, d, p, k), n.config.globalProperties.$ts = (i, d, p, k) => o.ts(i, d, p, k), n.config.globalProperties.$tc = (i, d, p) => o.tc(i, d, p), n.config.globalProperties.$tn = (i, d) => o.tn(i, d), n.config.globalProperties.$td = (i, d) => o.td(i, d), n.config.globalProperties.$tdr = (i, d) => o.tdr(i, d), n.config.globalProperties.$has = (i, d) => o.has(i, d), n.config.globalProperties.$i18n = o, n.component("I18nT", te), n.component("I18nLink", Y), n.component("I18nGroup", X), n.component("I18nSwitcher", ee);
653
+ }
654
+ };
655
+ }
656
+ function ue(t, e, a) {
636
657
  const r = e.map((o) => o.code), c = (o, u) => {
637
- const l = (typeof o == "string" ? o : o.path || "/").split("/").filter(Boolean), a = l[0];
638
- a !== void 0 && r.includes(a) && l.shift();
639
- const i = "/" + l.join("/");
640
- return u === n ? i : `/${u}${i === "/" ? "" : i}`;
658
+ const l = (typeof o == "string" ? o : o.path || "/").split("/").filter(Boolean), n = l[0];
659
+ n !== void 0 && r.includes(n) && l.shift();
660
+ const i = `/${l.join("/")}`;
661
+ return u === a ? i : `/${u}${i === "/" ? "" : i}`;
641
662
  };
642
663
  return {
643
664
  linkComponent: Q,
@@ -659,18 +680,18 @@ function ue(t, e, n) {
659
680
  }
660
681
  export {
661
682
  he as FormatService,
662
- B as I18nDefaultLocaleKey,
663
- te as I18nGroup,
683
+ z as I18nDefaultLocaleKey,
684
+ X as I18nGroup,
664
685
  D as I18nInjectionKey,
665
- ee as I18nLink,
666
- K as I18nLocalesKey,
667
- ne as I18nSwitcher,
668
- Y as I18nT,
669
- X as VueI18n,
670
- ce as createI18n,
686
+ Y as I18nLink,
687
+ V as I18nLocalesKey,
688
+ ee as I18nSwitcher,
689
+ te as I18nT,
690
+ ae as VueI18n,
691
+ se as createI18n,
671
692
  ue as createVueRouterAdapter,
672
693
  ge as defaultPlural,
673
694
  ye as interpolate,
674
- ae as useI18n,
675
- se as useLocaleHead
695
+ ne as useI18n,
696
+ ce as useLocaleHead
676
697
  };
@@ -1,6 +1,6 @@
1
+ import { Locale } from '@i18n-micro/types';
1
2
  import { InjectionKey } from 'vue';
2
3
  import { VueI18n } from './composer';
3
- import { Locale } from '@i18n-micro/types';
4
4
  import { I18nRoutingStrategy } from './router/types';
5
5
  export declare const I18nInjectionKey: InjectionKey<VueI18n>;
6
6
  export declare const I18nLocalesKey: InjectionKey<Locale[]>;
package/dist/plugin.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import { Locale } from '@i18n-micro/types';
1
2
  import { Plugin } from 'vue';
2
3
  import { VueI18n, VueI18nOptions } from './composer';
3
- import { Locale } from '@i18n-micro/types';
4
4
  import { I18nRoutingStrategy } from './router/types';
5
5
  export interface CreateI18nOptions extends VueI18nOptions {
6
6
  routingStrategy?: I18nRoutingStrategy;
@@ -1,6 +1,6 @@
1
+ import { Locale } from '@i18n-micro/types';
1
2
  import { Router } from 'vue-router';
2
3
  import { I18nRoutingStrategy } from './types';
3
- import { Locale } from '@i18n-micro/types';
4
4
  /**
5
5
  * Factory for Vue Router adapter
6
6
  * Implements routing utilities for Vue Router
@@ -1,5 +1,5 @@
1
- import { VueI18n } from './composer';
2
1
  import { Locale } from '@i18n-micro/types';
2
+ import { VueI18n } from './composer';
3
3
  export interface UseI18nOptions {
4
4
  locales?: Locale[];
5
5
  defaultLocale?: string;
@@ -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
@@ -9,9 +9,6 @@ declare module '@vue/runtime-core' {
9
9
  $td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string
10
10
  $tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string
11
11
  $has: (key: TranslationKey, routeName?: string) => boolean
12
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
12
  $i18n: any
14
13
  }
15
14
  }
16
-
17
- export {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-micro/vue",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
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.0",
23
- "@i18n-micro/types": "1.1.0"
22
+ "@i18n-micro/core": "1.2.0",
23
+ "@i18n-micro/types": "1.1.5"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "vue": "^3.5.25",