UNPKG

@i18n-pro/vue2

Version:

An out-of-the-box, lightweight i18n auto-translation solution for Vue 2

3 lines (2 loc) 2.84 kB
// @i18n-pro/vue2 v2.0.0 2025/9/6 17:49:43 MIT@Copyright (c) 2023-present Eyelly Wu <https://github.com/eyelly-wu> import{initI18n as t}from"i18n-pro";function n(t,n,e,r){return new(e||(e=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function c(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(a,c)}u((r=r.apply(t,n||[])).next())}))}function e(t,n){var e,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(u){return function(c){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(e=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=n.call(t,a)}catch(t){c=[6,t],r=0}finally{e=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}}var r=[];function o(o){return function(i){var a,c=this,u=o.namespace;if(!r.includes(u)){r.push(u);var l=o.with$,f=void 0===l||l,s=function(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(e[r[o]]=t[r[o]])}return e}(o,["with$"]),p=t(s),h=p.t,v=p.setI18n,y=f?"$":"",b=[],d=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return n(c,void 0,void 0,(function(){var n;return e(this,(function(e){switch(e.label){case 0:return[4,v.apply(void 0,t)];case 1:return n=e.sent(),b.forEach((function(t){t._t=h.withLocale(),t._i18nState=n})),[2,n]}}))}))};i.mixin({beforeCreate:function(){var t,n;b.push(this),null===(t=i.util)||void 0===t||t.defineReactive(this,"_t",h),null===(n=i.util)||void 0===n||n.defineReactive(this,"_i18nState",s)},destroyed:function(){var t=this;b=b.filter((function(n){return n!=t}))}}),Object.defineProperties(i.prototype,((a={})["".concat(y,"setI18n")]={get:function(){return d}},a["".concat(y,"t")]={get:function(){return this._t}},a["".concat(y,"i18nState")]={get:function(){return this._i18nState}},a))}}}export{o as createI18n};