6 lines
16 KiB
JavaScript
6 lines
16 KiB
JavaScript
/*!
|
|
* vue-i18n v7.3.2
|
|
* (c) 2017 kazuya kawaguchi
|
|
* Released under the MIT License.
|
|
*/
|
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueI18n=e()}(this,function(){"use strict";function t(t,e){"undefined"!=typeof console&&(console.warn("[vue-i18n] "+t),e&&console.warn(e.stack))}function e(t){return null!==t&&"object"==typeof t}function n(t){return M.call(t)===N}function r(t){return null===t||void 0===t}function i(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var r=null,i=null;return 1===t.length?e(t[0])||Array.isArray(t[0])?i=t[0]:"string"==typeof t[0]&&(r=t[0]):2===t.length&&("string"==typeof t[0]&&(r=t[0]),(e(t[1])||Array.isArray(t[1]))&&(i=t[1])),{locale:r,params:i}}function a(t){return t?t>1?1:0:1}function o(t,e){return t=Math.abs(t),2===e?a(t):t?Math.min(t,2):0}function s(t,e){if(!t&&"string"!=typeof t)return null;var n=t.split("|");return e=o(e,n.length),n[e]?n[e].trim():t}function l(t){return JSON.parse(JSON.stringify(t))}function c(t,e){if(t.length){var n=t.indexOf(e);if(n>-1)return t.splice(n,1)}}function u(t,e){return W.call(t,e)}function f(t){for(var n=arguments,r=Object(t),i=1;i<arguments.length;i++){var a=n[i];if(void 0!==a&&null!==a){var o=void 0;for(o in a)u(a,o)&&(e(a[o])?r[o]=f(r[o],a[o]):r[o]=a[o])}}return r}function h(t,n){if(t===n)return!0;var r=e(t),i=e(n);if(!r||!i)return!r&&!i&&String(t)===String(n);try{var a=Array.isArray(t),o=Array.isArray(n);if(a&&o)return t.length===n.length&&t.every(function(t,e){return h(t,n[e])});if(a||o)return!1;var s=Object.keys(t),l=Object.keys(n);return s.length===l.length&&s.every(function(e){return h(t[e],n[e])})}catch(t){return!1}}function p(t){t.prototype.$t=function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];var r=this.$i18n;return r._t.apply(r,[t,r.locale,r._getMessages(),this].concat(e))},t.prototype.$tc=function(t,e){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];var i=this.$i18n;return i._tc.apply(i,[t,i.locale,i._getMessages(),this,e].concat(n))},t.prototype.$te=function(t,e){var n=this.$i18n;return n._te(t,n.locale,n._getMessages(),e)},t.prototype.$d=function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return(r=this.$i18n).d.apply(r,[t].concat(e));var r},t.prototype.$n=function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return(r=this.$i18n).n.apply(r,[t].concat(e));var r}}function _(t,e,n){v(t,n)&&y(t,e,n)}function m(t,e,n,r){v(t,n)&&(g(t,n)&&h(e.value,e.oldValue)||y(t,e,n))}function v(e,n){var r=n.context;return r?!!r.$i18n||(t("not exist VueI18n instance in Vue instance"),!1):(t("not exist Vue instance in VNode context"),!1)}function g(t,e){var n=e.context;return t._locale===n.$i18n.locale}function y(e,n,r){var i=n.value,a=d(i),o=a.path,s=a.locale,l=a.args;if(!o&&!s&&!l)return void t("not support value type");if(!o)return void t("required `path` in v-t directive");var c=r.context;e._vt=e.textContent=(u=c.$i18n).t.apply(u,[o].concat(b(s,l))),e._locale=c.$i18n.locale;var u}function d(t){var e,r,i;return"string"==typeof t?e=t:n(t)&&(e=t.path,r=t.locale,i=t.args),{path:e,locale:r,args:i}}function b(t,e){var r=[];return t&&r.push(t),e&&(Array.isArray(e)||n(e))&&r.push(e),r}function F(t){O=t;O.version&&Number(O.version.split(".")[0]);F.installed=!0,Object.defineProperty(O.prototype,"$i18n",{get:function(){return this._i18n}}),p(O),O.mixin(S),O.directive("t",{bind:_,update:m}),O.component(V.name,V);var e=O.config.optionMergeStrategies;e.i18n=e.methods}function w(t){for(var e=[],n=0,r="";n<t.length;){var i=t[n++];if("{"===i){r&&e.push({type:"text",value:r}),r="";var a="";for(i=t[n++];"}"!==i;)a+=i,i=t[n++];var o=E.test(a)?"list":R.test(a)?"named":"unknown";e.push({value:a,type:o})}else"%"===i?"{"!==t[n]&&(r+=i):r+=i}return r&&e.push({type:"text",value:r}),e}function $(t,n){var r=[],i=0,a=Array.isArray(n)?"list":e(n)?"named":"unknown";if("unknown"===a)return r;for(;i<t.length;){var o=t[i];switch(o.type){case"text":r.push(o.value);break;case"list":r.push(n[parseInt(o.value,10)]);break;case"named":"named"===a&&r.push(n[o.value])}i++}return r}function k(t){return Y.test(t)}function T(t){var e=t.charCodeAt(0);return e!==t.charCodeAt(t.length-1)||34!==e&&39!==e?t:t.slice(1,-1)}function x(t){if(void 0===t||null===t)return"eof";var e=t.charCodeAt(0);switch(e){case 91:case 93:case 46:case 34:case 39:case 48:return t;case 95:case 36:case 45:return"ident";case 32:case 9:case 10:case 13:case 160:case 65279:case 8232:case 8233:return"ws"}return e>=97&&e<=122||e>=65&&e<=90?"ident":e>=49&&e<=57?"number":"else"}function D(t){var e=t.trim();return("0"!==t.charAt(0)||!isNaN(t))&&(k(e)?T(e):"*"+e)}function L(t){var e,n,r,i,a,o,s,l=[],c=-1,u=q,f=0,h=[];for(h[z]=function(){void 0!==n&&(l.push(n),n=void 0)},h[P]=function(){void 0===n?n=r:n+=r},h[J]=function(){h[P](),f++},h[U]=function(){if(f>0)f--,u=B,h[P]();else{if(f=0,!1===(n=D(n)))return!1;h[z]()}};null!==u;)if(c++,"\\"!==(e=t[c])||!function(){var e=t[c+1];if(u===G&&"'"===e||u===H&&'"'===e)return c++,r="\\"+e,h[P](),!0}()){if(i=x(e),s=X[u],(a=s[i]||s.else||Q)===Q)return;if(u=a[0],(o=h[a[1]])&&(r=a[2],r=void 0===r?e:r,!1===o()))return;if(u===K)return l}}function A(t){return!!Array.isArray(t)&&0===t.length}var O,M=Object.prototype.toString,N="[object Object]",W=Object.prototype.hasOwnProperty,j="undefined"!=typeof Intl&&void 0!==Intl.DateTimeFormat,I="undefined"!=typeof Intl&&void 0!==Intl.NumberFormat,S={beforeCreate:function(){var t=this.$options;if(t.i18n=t.i18n||(t.__i18n?{}:null),t.i18n){if(t.i18n instanceof tt){if(t.__i18n)try{var e={};t.__i18n.forEach(function(t){e=f(e,JSON.parse(t))}),Object.keys(e).forEach(function(n){t.i18n.mergeLocaleMessage(n,e[n])})}catch(t){}this._i18n=t.i18n,this._i18nWatcher=this._i18n.watchI18nData(),this._i18n.subscribeDataChanging(this),this._subscribing=!0}else if(n(t.i18n)){if(this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof tt&&(t.i18n.root=this.$root.$i18n,t.i18n.fallbackLocale=this.$root.$i18n.fallbackLocale,t.i18n.silentTranslationWarn=this.$root.$i18n.silentTranslationWarn),t.__i18n)try{var r={};t.__i18n.forEach(function(t){r=f(r,JSON.parse(t))}),t.i18n.messages=r}catch(t){}this._i18n=new tt(t.i18n),this._i18nWatcher=this._i18n.watchI18nData(),this._i18n.subscribeDataChanging(this),this._subscribing=!0,(void 0===t.i18n.sync||t.i18n.sync)&&(this._localeWatcher=this.$i18n.watchLocale())}}else this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof tt?(this._i18n=this.$root.$i18n,this._i18n.subscribeDataChanging(this),this._subscribing=!0):t.parent&&t.parent.$i18n&&t.parent.$i18n instanceof tt&&(this._i18n=t.parent.$i18n,this._i18n.subscribeDataChanging(this),this._subscribing=!0)},beforeDestroy:function(){this._i18n&&(this._subscribing&&(this._i18n.unsubscribeDataChanging(this),delete this._subscribing),this._i18nWatcher&&(this._i18nWatcher(),delete this._i18nWatcher),this._localeWatcher&&(this._localeWatcher(),delete this._localeWatcher),this._i18n=null)}},V={name:"i18n",functional:!0,props:{tag:{type:String,default:"span"},path:{type:String,required:!0},locale:{type:String},places:{type:[Array,Object]}},render:function(e,n){var r=n.props,i=n.data,a=n.children,o=n.parent,s=o.$i18n;if(a=(a||[]).filter(function(t){return t.tag||(t.text=t.text.trim())}),!s)return a;var l=r.path,c=r.locale,u={},f=r.places||{},h=Array.isArray(f)?f.length>0:Object.keys(f).length>0,p=a.every(function(t){if(t.data&&t.data.attrs){var e=t.data.attrs.place;return void 0!==e&&""!==e}});return h&&a.length>0&&!p&&t("If places prop is set, all child elements must have place prop set."),Array.isArray(f)?f.forEach(function(t,e){u[e]=t}):Object.keys(f).forEach(function(t){u[t]=f[t]}),a.forEach(function(t,e){var n=p?""+t.data.attrs.place:""+e;u[n]=t}),e(r.tag,i,s.i(l,c,u))}},C=function(){this._caches=Object.create(null)};C.prototype.interpolate=function(t,e){var n=this._caches[t];return n||(n=w(t),this._caches[t]=n),$(n,e)};var E=/^(\d)+/,R=/^(\w)+/,P=0,z=1,J=2,U=3,q=0,B=4,G=5,H=6,K=7,Q=8,X=[];X[q]={ws:[q],ident:[3,P],"[":[B],eof:[K]},X[1]={ws:[1],".":[2],"[":[B],eof:[K]},X[2]={ws:[2],ident:[3,P],0:[3,P],number:[3,P]},X[3]={ident:[3,P],0:[3,P],number:[3,P],ws:[1,z],".":[2,z],"[":[B,z],eof:[K,z]},X[B]={"'":[G,P],'"':[H,P],"[":[B,J],"]":[1,U],eof:Q,else:[B,P]},X[G]={"'":[B,P],eof:Q,else:[G,P]},X[H]={'"':[B,P],eof:Q,else:[H,P]};var Y=/^\s?(true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/,Z=function(){this._cache=Object.create(null)};Z.prototype.parsePath=function(t){var e=this._cache[t];return e||(e=L(t))&&(this._cache[t]=e),e||[]},Z.prototype.getPathValue=function(t,n){if(!e(t))return null;var r=this.parsePath(n);if(A(r))return null;for(var i=r.length,a=t,o=0;o<i;){var s=a[r[o]];if(void 0===s){a=null;break}a=s,o++}return a};var tt=function(t){var e=this;void 0===t&&(t={});var n=t.locale||"en-US",i=t.fallbackLocale||"en-US",a=t.messages||{},o=t.dateTimeFormats||{},s=t.numberFormats||{};this._vm=null,this._formatter=t.formatter||new C,this._missing=t.missing||null,this._root=t.root||null,this._sync=void 0===t.sync||!!t.sync,this._fallbackRoot=void 0===t.fallbackRoot||!!t.fallbackRoot,this._silentTranslationWarn=void 0!==t.silentTranslationWarn&&!!t.silentTranslationWarn,this._dateTimeFormatters={},this._numberFormatters={},this._path=new Z,this._dataListeners=[],this._exist=function(t,n){return!(!t||!n)&&!r(e._path.getPathValue(t,n))},this._initVM({locale:n,fallbackLocale:i,messages:a,dateTimeFormats:o,numberFormats:s})},et={vm:{},messages:{},dateTimeFormats:{},numberFormats:{},locale:{},fallbackLocale:{},missing:{},formatter:{},silentTranslationWarn:{}};return tt.prototype._initVM=function(t){var e=O.config.silent;O.config.silent=!0,this._vm=new O({data:t}),O.config.silent=e},tt.prototype.subscribeDataChanging=function(t){this._dataListeners.push(t)},tt.prototype.unsubscribeDataChanging=function(t){c(this._dataListeners,t)},tt.prototype.watchI18nData=function(){var t=this;return this._vm.$watch("$data",function(){for(var e=t._dataListeners.length;e--;)O.nextTick(function(){t._dataListeners[e]&&t._dataListeners[e].$forceUpdate()})},{deep:!0})},tt.prototype.watchLocale=function(){if(!this._sync||!this._root)return null;var t=this._vm;return this._root.vm.$watch("locale",function(e){t.$set(t,"locale",e),t.$forceUpdate()},{immediate:!0})},et.vm.get=function(){return this._vm},et.messages.get=function(){return l(this._getMessages())},et.dateTimeFormats.get=function(){return l(this._getDateTimeFormats())},et.numberFormats.get=function(){return l(this._getNumberFormats())},et.locale.get=function(){return this._vm.locale},et.locale.set=function(t){this._vm.$set(this._vm,"locale",t)},et.fallbackLocale.get=function(){return this._vm.fallbackLocale},et.fallbackLocale.set=function(t){this._vm.$set(this._vm,"fallbackLocale",t)},et.missing.get=function(){return this._missing},et.missing.set=function(t){this._missing=t},et.formatter.get=function(){return this._formatter},et.formatter.set=function(t){this._formatter=t},et.silentTranslationWarn.get=function(){return this._silentTranslationWarn},et.silentTranslationWarn.set=function(t){this._silentTranslationWarn=t},tt.prototype._getMessages=function(){return this._vm.messages},tt.prototype._getDateTimeFormats=function(){return this._vm.dateTimeFormats},tt.prototype._getNumberFormats=function(){return this._vm.numberFormats},tt.prototype._warnDefault=function(t,e,n,i){return r(n)?(this.missing&&this.missing.apply(null,[t,e,i]),e):n},tt.prototype._isFallbackRoot=function(t){return!t&&!r(this._root)&&this._fallbackRoot},tt.prototype._interpolate=function(t,e,i,a,o,s){if(!e)return null;var l=this._path.getPathValue(e,i);if(Array.isArray(l))return l;var c;if(r(l)){if(!n(e))return null;if("string"!=typeof(c=e[i]))return null}else{if("string"!=typeof l)return null;c=l}return c.indexOf("@:")>=0&&(c=this._link(t,e,c,a,o,s)),s?this._render(c,o,s):c},tt.prototype._link=function(t,e,n,r,i,a){var o=this,s=n,l=s.match(/(@:[\w\-_|.]+)/g);for(var c in l)if(l.hasOwnProperty(c)){var u=l[c],f=u.substr(2),h=o._interpolate(t,e,f,r,"raw"===i?"string":i,"raw"===i?void 0:a);if(o._isFallbackRoot(h)){if(!o._root)throw Error("unexpected error");var p=o._root;h=p._translate(p._getMessages(),p.locale,p.fallbackLocale,f,r,i,a)}h=o._warnDefault(t,f,h,r),s=h?s.replace(u,h):s}return s},tt.prototype._render=function(t,e,n){var r=this._formatter.interpolate(t,n);return"string"===e?r.join(""):r},tt.prototype._translate=function(t,e,n,i,a,o,s){var l=this._interpolate(e,t[e],i,a,o,s);return r(l)?(l=this._interpolate(n,t[n],i,a,o,s),r(l)?null:l):l},tt.prototype._t=function(t,e,n,r){for(var a=[],o=arguments.length-4;o-- >0;)a[o]=arguments[o+4];if(!t)return"";var s=i.apply(void 0,a),l=s.locale||e,c=this._translate(n,l,this.fallbackLocale,t,r,"string",s.params);if(this._isFallbackRoot(c)){if(!this._root)throw Error("unexpected error");return(u=this._root).t.apply(u,[t].concat(a))}return this._warnDefault(l,t,c,r);var u},tt.prototype.t=function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return(r=this)._t.apply(r,[t,this.locale,this._getMessages(),null].concat(e));var r},tt.prototype._i=function(t,e,n,r,i){var a=this._translate(n,e,this.fallbackLocale,t,r,"raw",i);if(this._isFallbackRoot(a)){if(!this._root)throw Error("unexpected error");return this._root.i(t,e,i)}return this._warnDefault(e,t,a,r)},tt.prototype.i=function(t,e,n){return t?("string"!=typeof e&&(e=this.locale),this._i(t,e,this._getMessages(),null,n)):""},tt.prototype._tc=function(t,e,n,r,i){for(var a=[],o=arguments.length-5;o-- >0;)a[o]=arguments[o+5];return t?(void 0===i&&(i=1),s((l=this)._t.apply(l,[t,e,n,r].concat(a)),i)):"";var l},tt.prototype.tc=function(t,e){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];return(i=this)._tc.apply(i,[t,this.locale,this._getMessages(),null,e].concat(n));var i},tt.prototype._te=function(t,e,n){for(var r=[],a=arguments.length-3;a-- >0;)r[a]=arguments[a+3];var o=i.apply(void 0,r).locale||e;return this._exist(n[o],t)},tt.prototype.te=function(t,e){return this._te(t,this.locale,this._getMessages(),e)},tt.prototype.getLocaleMessage=function(t){return l(this._vm.messages[t]||{})},tt.prototype.setLocaleMessage=function(t,e){this._vm.messages[t]=e},tt.prototype.mergeLocaleMessage=function(t,e){this._vm.messages[t]=O.util.extend(this._vm.messages[t]||{},e)},tt.prototype.getDateTimeFormat=function(t){return l(this._vm.dateTimeFormats[t]||{})},tt.prototype.setDateTimeFormat=function(t,e){this._vm.dateTimeFormats[t]=e},tt.prototype.mergeDateTimeFormat=function(t,e){this._vm.dateTimeFormats[t]=O.util.extend(this._vm.dateTimeFormats[t]||{},e)},tt.prototype._localizeDateTime=function(t,e,n,i,a){var o=e,s=i[o];if((r(s)||r(s[a]))&&(o=n,s=i[o]),r(s)||r(s[a]))return null;var l=s[a],c=o+"__"+a,u=this._dateTimeFormatters[c];return u||(u=this._dateTimeFormatters[c]=new Intl.DateTimeFormat(o,l)),u.format(t)},tt.prototype._d=function(t,e,n){if(!n)return new Intl.DateTimeFormat(e).format(t);var r=this._localizeDateTime(t,e,this.fallbackLocale,this._getDateTimeFormats(),n);if(this._isFallbackRoot(r)){if(!this._root)throw Error("unexpected error");return this._root.d(t,n,e)}return r||""},tt.prototype.d=function(t){for(var n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];var i=this.locale,a=null;return 1===n.length?"string"==typeof n[0]?a=n[0]:e(n[0])&&(n[0].locale&&(i=n[0].locale),n[0].key&&(a=n[0].key)):2===n.length&&("string"==typeof n[0]&&(a=n[0]),"string"==typeof n[1]&&(i=n[1])),this._d(t,i,a)},tt.prototype.getNumberFormat=function(t){return l(this._vm.numberFormats[t]||{})},tt.prototype.setNumberFormat=function(t,e){this._vm.numberFormats[t]=e},tt.prototype.mergeNumberFormat=function(t,e){this._vm.numberFormats[t]=O.util.extend(this._vm.numberFormats[t]||{},e)},tt.prototype._localizeNumber=function(t,e,n,i,a){var o=e,s=i[o];if((r(s)||r(s[a]))&&(o=n,s=i[o]),r(s)||r(s[a]))return null;var l=s[a],c=o+"__"+a,u=this._numberFormatters[c];return u||(u=this._numberFormatters[c]=new Intl.NumberFormat(o,l)),u.format(t)},tt.prototype._n=function(t,e,n){if(!n)return new Intl.NumberFormat(e).format(t);var r=this._localizeNumber(t,e,this.fallbackLocale,this._getNumberFormats(),n);if(this._isFallbackRoot(r)){if(!this._root)throw Error("unexpected error");return this._root.n(t,n,e)}return r||""},tt.prototype.n=function(t){for(var n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];var i=this.locale,a=null;return 1===n.length?"string"==typeof n[0]?a=n[0]:e(n[0])&&(n[0].locale&&(i=n[0].locale),n[0].key&&(a=n[0].key)):2===n.length&&("string"==typeof n[0]&&(a=n[0]),"string"==typeof n[1]&&(i=n[1])),this._n(t,i,a)},Object.defineProperties(tt.prototype,et),tt.availabilities={dateTimeFormat:j,numberFormat:I},tt.install=F,tt.version="7.3.2","undefined"!=typeof window&&window.Vue&&window.Vue.use(tt),tt}); |