UNPKG

@i18n-pro/vue

Version:

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

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