Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-i18n

Package Overview
Dependencies
Maintainers
1
Versions
355
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-i18n - npm Package Compare versions

Comparing version 6.0.0-alpha.2 to 6.0.0-alpha.3

15

CHANGELOG.md

@@ -0,1 +1,16 @@

<a name="6.0.0-alpha.3"></a>
# [6.0.0-alpha.3](https://github.com/kazupon/vue-i18n/compare/v6.0.0-alpha.2...v6.0.0-alpha.3) (2017-03-08)
### :star: New Features
* add `sync` option ([5c46c07](https://github.com/kazupon/vue-i18n/commit/5c46c07))
### :zap: Improvements
* **mixin:** add error throwings and a warning ([0e4ac39](https://github.com/kazupon/vue-i18n/commit/0e4ac39))
<a name="6.0.0-alpha.2"></a>

@@ -2,0 +17,0 @@ # [6.0.0-alpha.2](https://github.com/kazupon/vue-i18n/compare/v6.0.0-alpha.1...v6.0.0-alpha.2) (2017-02-27)

8

decls/i18n.js

@@ -14,3 +14,4 @@ declare type Dictionary<T> = { [key: string]: T }

root?: I18n,
fallbackRoot?: boolean
fallbackRoot?: boolean,
sync?: boolean
}

@@ -21,2 +22,3 @@

static version: string,
get vm() :any,
get locale (): string,

@@ -34,3 +36,5 @@ set locale (locale: string): void,

tc (key: string, choice?: number, ...args: any): any,
te (key: string, ...args: any): boolean
te (key: string, ...args: any): boolean,
watchLocale (): any,
unwatchLocale (): boolean
}

@@ -37,0 +41,0 @@

/*!
* vue-i18n v6.0.0-alpha.2
* vue-i18n v6.0.0-alpha.3
* (c) 2017 kazuya kawaguchi

@@ -40,2 +40,23 @@ * Released under the MIT License.

function funcName (f) {
if (f.name) { return f.name }
var match = /^\s*function\s*([^\(]*)/im.exec(f.toString());
return match ? match[1] : ''
}
function ctorName (obj) {
var str = toString.call(obj).slice(8, -1);
if ((str === 'Object' || str === 'Error') && obj.constructor) {
return funcName(obj.constructor)
}
return str
}
function typeName (val) {
if (val === null) { return 'null' }
var type = typeof val;
if (type === 'object') { return ctorName(val) }
return type
}
function isNull (val) {

@@ -101,3 +122,6 @@ return val === null || val === undefined

// HACK: add dependency tracking !!
if (!this.$i18n) {
throw Error("Failed in $t due to not find VueI18n instance")
}
// add dependency tracking !!
var locale = this.$i18n.locale;

@@ -117,3 +141,6 @@ var messages = this.$i18n.messages;

// HACK: add dependency tracking !!
if (!this.$i18n) {
throw Error("Failed in $tc due to not find VueI18n instance")
}
// add dependency tracking !!
var locale = this.$i18n.locale;

@@ -133,3 +160,6 @@ var messages = this.$i18n.messages;

// HACK: add dependency tracking !!
if (!this.$i18n) {
throw Error("Failed in $te due to not find VueI18n instance")
}
// add dependency tracking !!
var locale = this.$i18n.locale;

@@ -150,12 +180,19 @@ var messages = this.$i18n.messages;

if (options.i18n) {
if (options.i18n instanceof VueI18n) {
if (typeName(options.i18n) === 'VueI18n') {
this.$i18n = options.i18n;
} else {
} else if (isPlainObject(options.i18n)) {
// component local i18n
if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
if (this.$root && this.$root.$i18n && typeName(this.$root.$i18n) === 'VueI18n') {
options.i18n.root = this.$root.$i18n;
}
this.$i18n = new VueI18n(options.i18n);
if (options.i18n.sync) {
this._localeWatcher = this.$i18n.watchLocale();
}
} else {
if (process.env.NODE_ENV !== 'production') {
warn("Cannot be interpreted 'i18n' option.");
}
}
} else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
} else if (this.$root && this.$root.$i18n && typeName(this.$root.$i18n) === 'VueI18n') {
// root i18n

@@ -166,3 +203,8 @@ this.$i18n = this.$root.$i18n;

beforeDestroy: function beforeDestroy () {
destroyed: function destroyed () {
if (this._localeWatcher) {
this.$i18n.unwatchLocale();
delete this._localeWatcher;
}
this.$i18n = null;

@@ -172,2 +214,4 @@ }

/* */
var Asset = function (Vue) {

@@ -621,2 +665,3 @@ var strats = Vue.config.optionMergeStrategies;

this._root = options.root || null;
this._sync = options.sync || false;
this._fallbackRoot = options.fallbackRoot || false;

@@ -632,3 +677,3 @@

var prototypeAccessors = { messages: {},locale: {},fallbackLocale: {},missing: {},formatter: {} };
var prototypeAccessors = { vm: {},messages: {},locale: {},fallbackLocale: {},missing: {},formatter: {} };

@@ -642,2 +687,22 @@ VueI18n.prototype._resetVM = function _resetVM (data) {

VueI18n.prototype.watchLocale = function watchLocale () {
if (!this._sync || !this._root) { return null }
var target = this._vm;
this._watcher = this._root.vm.$watch('locale', function (val) {
target.$set(target, 'locale', val);
}, { immediate: true });
return this._watcher
};
VueI18n.prototype.unwatchLocale = function unwatchLocale () {
if (!this._sync || !this._watcher) { return false }
if (this._watcher) {
this._watcher();
delete this._watcher;
}
return true
};
prototypeAccessors.vm.get = function () { return this._vm };
prototypeAccessors.messages.get = function () { return this._vm.$data.messages };

@@ -763,5 +828,5 @@ prototypeAccessors.messages.set = function (messages) { this._vm.$set(this._vm, 'messages', messages); };

var ref;
};
};
VueI18n.prototype._tc = function _tc (key, _locale, messages, host, choice) {
VueI18n.prototype._tc = function _tc (key, _locale, messages, host, choice) {
var args = [], len = arguments.length - 5;

@@ -800,3 +865,3 @@ while ( len-- > 0 ) args[ len ] = arguments[ len + 5 ];

return (ref = this)._te.apply(ref, [ key, this.locale, this.messages ].concat( args ))
return (ref = this)._te.apply(ref, [ key, this.locale, this.messages ].concat( args ))
var ref;

@@ -803,0 +868,0 @@ };

/*!
* vue-i18n v6.0.0-alpha.2
* vue-i18n v6.0.0-alpha.3
* (c) 2017 kazuya kawaguchi

@@ -44,2 +44,23 @@ * Released under the MIT License.

function funcName (f) {
if (f.name) { return f.name }
var match = /^\s*function\s*([^\(]*)/im.exec(f.toString());
return match ? match[1] : ''
}
function ctorName (obj) {
var str = toString.call(obj).slice(8, -1);
if ((str === 'Object' || str === 'Error') && obj.constructor) {
return funcName(obj.constructor)
}
return str
}
function typeName (val) {
if (val === null) { return 'null' }
var type = typeof val;
if (type === 'object') { return ctorName(val) }
return type
}
function isNull (val) {

@@ -105,3 +126,6 @@ return val === null || val === undefined

// HACK: add dependency tracking !!
if (!this.$i18n) {
throw Error("Failed in $t due to not find VueI18n instance")
}
// add dependency tracking !!
var locale = this.$i18n.locale;

@@ -121,3 +145,6 @@ var messages = this.$i18n.messages;

// HACK: add dependency tracking !!
if (!this.$i18n) {
throw Error("Failed in $tc due to not find VueI18n instance")
}
// add dependency tracking !!
var locale = this.$i18n.locale;

@@ -137,3 +164,6 @@ var messages = this.$i18n.messages;

// HACK: add dependency tracking !!
if (!this.$i18n) {
throw Error("Failed in $te due to not find VueI18n instance")
}
// add dependency tracking !!
var locale = this.$i18n.locale;

@@ -154,12 +184,19 @@ var messages = this.$i18n.messages;

if (options.i18n) {
if (options.i18n instanceof VueI18n) {
if (typeName(options.i18n) === 'VueI18n') {
this.$i18n = options.i18n;
} else {
} else if (isPlainObject(options.i18n)) {
// component local i18n
if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
if (this.$root && this.$root.$i18n && typeName(this.$root.$i18n) === 'VueI18n') {
options.i18n.root = this.$root.$i18n;
}
this.$i18n = new VueI18n(options.i18n);
if (options.i18n.sync) {
this._localeWatcher = this.$i18n.watchLocale();
}
} else {
{
warn("Cannot be interpreted 'i18n' option.");
}
}
} else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
} else if (this.$root && this.$root.$i18n && typeName(this.$root.$i18n) === 'VueI18n') {
// root i18n

@@ -170,3 +207,8 @@ this.$i18n = this.$root.$i18n;

beforeDestroy: function beforeDestroy () {
destroyed: function destroyed () {
if (this._localeWatcher) {
this.$i18n.unwatchLocale();
delete this._localeWatcher;
}
this.$i18n = null;

@@ -176,2 +218,4 @@ }

/* */
var Asset = function (Vue) {

@@ -625,2 +669,3 @@ var strats = Vue.config.optionMergeStrategies;

this._root = options.root || null;
this._sync = options.sync || false;
this._fallbackRoot = options.fallbackRoot || false;

@@ -636,3 +681,3 @@

var prototypeAccessors = { messages: {},locale: {},fallbackLocale: {},missing: {},formatter: {} };
var prototypeAccessors = { vm: {},messages: {},locale: {},fallbackLocale: {},missing: {},formatter: {} };

@@ -646,2 +691,22 @@ VueI18n.prototype._resetVM = function _resetVM (data) {

VueI18n.prototype.watchLocale = function watchLocale () {
if (!this._sync || !this._root) { return null }
var target = this._vm;
this._watcher = this._root.vm.$watch('locale', function (val) {
target.$set(target, 'locale', val);
}, { immediate: true });
return this._watcher
};
VueI18n.prototype.unwatchLocale = function unwatchLocale () {
if (!this._sync || !this._watcher) { return false }
if (this._watcher) {
this._watcher();
delete this._watcher;
}
return true
};
prototypeAccessors.vm.get = function () { return this._vm };
prototypeAccessors.messages.get = function () { return this._vm.$data.messages };

@@ -767,5 +832,5 @@ prototypeAccessors.messages.set = function (messages) { this._vm.$set(this._vm, 'messages', messages); };

var ref;
};
};
VueI18n.prototype._tc = function _tc (key, _locale, messages, host, choice) {
VueI18n.prototype._tc = function _tc (key, _locale, messages, host, choice) {
var args = [], len = arguments.length - 5;

@@ -804,3 +869,3 @@ while ( len-- > 0 ) args[ len ] = arguments[ len + 5 ];

return (ref = this)._te.apply(ref, [ key, this.locale, this.messages ].concat( args ))
return (ref = this)._te.apply(ref, [ key, this.locale, this.messages ].concat( args ))
var ref;

@@ -812,3 +877,3 @@ };

VueI18n.install = install;
VueI18n.version = '6.0.0-alpha.2';
VueI18n.version = '6.0.0-alpha.3';

@@ -815,0 +880,0 @@ if (typeof window !== 'undefined' && window.Vue) {

/*!
* vue-i18n v6.0.0-alpha.2
* vue-i18n v6.0.0-alpha.3
* (c) 2017 kazuya kawaguchi
* Released under the MIT License.
*/
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.VueI18n=n()}(this,function(){"use strict";function t(t,n){"undefined"!=typeof console&&(console.warn("[vue-i18n] "+t),n&&console.warn(n.stack))}function n(t,n){return $.call(t,n)}function e(t){return null!==t&&"object"==typeof t}function r(t){return b.call(t)===w}function i(t){return null===t||void 0===t}function o(){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 s(t,n){return t=Math.abs(t),2===n?a(t):t?Math.min(t,2):0}function l(t,n){if(!t&&"string"!=typeof t)return null;var e=t.split("|");return n=s(n,e.length),e[n]?e[n].trim():t}function c(t){d=t;d.version&&Number(d.version.split(".")[0])||-1;c.installed=!0,d.mixin(k),A(d)}function u(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];return e=1===e.length&&"object"==typeof e[0]?e[0]:{},e&&e.hasOwnProperty||(e={}),t.replace(x,function(r,o,a,s){var l;return"{"===t[s-1]&&"}"===t[s+r.length]?a:(l=n(e,a)?e[a]:r,i(l)?"":l)})}function f(t){return q.test(t)}function h(t){var n=t.charCodeAt(0),e=t.charCodeAt(t.length-1);return n!==e||34!==n&&39!==n?t:t.slice(1,-1)}function p(t){if(void 0===t||null===t)return"eof";var n=t.charCodeAt(0);switch(n){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 n>=97&&n<=122||n>=65&&n<=90?"ident":n>=49&&n<=57?"number":"else"}function v(t){var n=t.trim();return("0"!==t.charAt(0)||!isNaN(t))&&(f(n)?h(n):"*"+n)}function g(t){function n(){var n=t[u+1];if(f===U&&"'"===n||f===z&&'"'===n)return u++,i="\\"+n,g[V](),!0}var e,r,i,o,a,s,l,c=[],u=-1,f=P,h=0,g=[];for(g[M]=function(){void 0!==r&&(c.push(r),r=void 0)},g[V]=function(){void 0===r?r=i:r+=i},g[R]=function(){g[V](),h++},g[C]=function(){if(h>0)h--,f=F,g[V]();else{if(h=0,r=v(r),r===!1)return!1;g[M]()}};null!==f;)if(u++,e=t[u],"\\"!==e||!n()){if(o=p(e),l=Z[f],a=l[o]||l.else||I,a===I)return;if(f=a[0],s=g[a[1]],s&&(i=a[2],i=void 0===i?e:i,s()===!1))return;if(f===E)return c}}function m(t){var n=L[t];return n||(n=g(t),n&&(L[t]=n)),n||[]}function y(t){if(null===t||void 0===t)return!0;if(Array.isArray(t)){if(t.length>0)return!1;if(0===t.length)return!0}else if(r(t))for(var e in t)if(n(t,e))return!1;return!0}function _(t,n){if(!e(t))return null;var r=m(n);if(y(r))return null;for(var i=r.length,o=null,a=t,s=0;s<i;){var l=a[r[s]];if(void 0===l){a=null;break}a=l,s++}return o=a}var d,$=Object.prototype.hasOwnProperty,b=Object.prototype.toString,w="[object Object]",k={computed:{$t:function(){var t=this,n=this.$i18n.locale,e=this.$i18n.messages;return function(r){for(var i=[],o=arguments.length-1;o-- >0;)i[o]=arguments[o+1];return(a=t.$i18n)._t.apply(a,[r,n,e,t].concat(i));var a}},$tc:function(){var t=this,n=this.$i18n.locale,e=this.$i18n.messages;return function(r,i){for(var o=[],a=arguments.length-2;a-- >0;)o[a]=arguments[a+2];return(s=t.$i18n)._tc.apply(s,[r,n,e,t,i].concat(o));var s}},$te:function(){var t=this,n=this.$i18n.locale,e=this.$i18n.messages;return function(r){for(var i=[],o=arguments.length-1;o-- >0;)i[o]=arguments[o+1];return(a=t.$i18n)._te.apply(a,[r,n,e].concat(i));var a}}},beforeCreate:function(){var t=this.$options;t.i18n?t.i18n instanceof B?this.$i18n=t.i18n:(this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof B&&(t.i18n.root=this.$root.$i18n),this.$i18n=new B(t.i18n)):this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof B&&(this.$i18n=this.$root.$i18n)},beforeDestroy:function(){this.$i18n=null}},A=function(t){var n=t.config.optionMergeStrategies;n&&(n.i18n=function(n,e){var r=Object.create(null);if(!e)return n;if(!n)return e;if(!e&!n)return r;t.util.extend(r,n);for(var i in e)r[i]=e[i];return r})},j=function(t){void 0===t&&(t={}),this._options=t},O={options:{}};O.options.get=function(){return this._options},j.prototype.format=function(t){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return u.apply(void 0,[t].concat(n))},Object.defineProperties(j.prototype,O);var x=/(%|)\{([0-9a-zA-Z_]+)\}/g,L=Object.create(null),V=0,M=1,R=2,C=3,P=0,S=1,D=2,N=3,F=4,U=5,z=6,E=7,I=8,Z=[];Z[P]={ws:[P],ident:[N,V],"[":[F],eof:[E]},Z[S]={ws:[S],".":[D],"[":[F],eof:[E]},Z[D]={ws:[D],ident:[N,V],0:[N,V],number:[N,V]},Z[N]={ident:[N,V],0:[N,V],number:[N,V],ws:[S,M],".":[D,M],"[":[F,M],eof:[E,M]},Z[F]={"'":[U,V],'"':[z,V],"[":[F,R],"]":[S,C],eof:I,else:[F,V]},Z[U]={"'":[F,V],eof:I,else:[U,V]},Z[z]={'"':[F,V],eof:I,else:[z,V]};var q=/^\s?(true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/,B=function(t){void 0===t&&(t={});var n=t.locale||"en-US",e=t.messages||{};this._vm=null,this._fallbackLocale=t.fallbackLocale||"en-US",this._formatter=t.formatter||new j,this._missing=t.missing,this._root=t.root||null,this._fallbackRoot=t.fallbackRoot||!1,this._exist=function(t,n){return!(!t||!n)&&!i(_(t,n))},this._resetVM({locale:n,messages:e})},G={messages:{},locale:{},fallbackLocale:{},missing:{},formatter:{}};return B.prototype._resetVM=function(t){var n=d.config.silent;d.config.silent=!0,this._vm=new d({data:t}),d.config.silent=n},G.messages.get=function(){return this._vm.$data.messages},G.messages.set=function(t){this._vm.$set(this._vm,"messages",t)},G.locale.get=function(){return this._vm.$data.locale},G.locale.set=function(t){this._vm.$set(this._vm,"locale",t)},G.fallbackLocale.get=function(){return this._fallbackLocale},G.fallbackLocale.set=function(t){this._fallbackLocale=t},G.missing.get=function(){return this._missing},G.missing.set=function(t){this._missing=t},G.formatter.get=function(){return this._formatter},G.formatter.set=function(t){this._formatter=t},B.prototype._warnDefault=function(t,n,e,r){return i(e)?(this.missing&&this.missing.apply(null,[t,n,r]),n):e},B.prototype._isFallbackRoot=function(t){return!t&&!i(this._root)&&this._fallbackRoot},B.prototype._interpolate=function(n,e,r){var o=this;if(!n)return null;var a=_(n,e);if(Array.isArray(a))return a;if(i(a)&&(a=n[e]),i(a))return null;if("string"!=typeof a)return t("Value of key '"+e+"' is not a string!"),null;if(a.indexOf("@:")>=0){var s=a.match(/(@:[\w|.]+)/g);for(var l in s){var c=s[l],u=c.substr(2),f=o._interpolate(n,u,r);a=a.replace(c,f)}}return r?this._format(a,r):a},B.prototype._format=function(t){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return(r=this._formatter).format.apply(r,[t].concat(n));var r},B.prototype._translate=function(t,n,e,r,o){var a=null;return a=this._interpolate(t[n],r,o),i(a)?(a=this._interpolate(t[e],r,o),i(a)?null:a):a},B.prototype._t=function(t,n,e,r){for(var i=[],a=arguments.length-4;a-- >0;)i[a]=arguments[a+4];if(!t)return"";var s=o.apply(void 0,i),l=s.locale||n,c=this._translate(e,l,this.fallbackLocale,t,s.params);if(this._isFallbackRoot(c)){if(!this._root)throw Error("unexpected error");return(u=this._root).t.apply(u,[t].concat(i))}return this._warnDefault(l,t,c,r);var u},B.prototype.t=function(t){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return(r=this)._t.apply(r,[t,this.locale,this.messages,null].concat(n));var r},B.prototype._tc=function(t,n,e,r,i){for(var o=[],a=arguments.length-5;a-- >0;)o[a]=arguments[a+5];return t?void 0!==i?l((s=this)._t.apply(s,[t,n,e,r].concat(o)),i):(c=this)._t.apply(c,[t,n,e,r].concat(o)):"";var s,c},B.prototype.tc=function(t,n){for(var e=[],r=arguments.length-2;r-- >0;)e[r]=arguments[r+2];return(i=this)._tc.apply(i,[t,this.locale,this.messages,null,n].concat(e));var i},B.prototype._te=function(t,n,e){for(var r=[],i=arguments.length-3;i-- >0;)r[i]=arguments[i+3];var a=o.apply(void 0,r).locale||n;return this._exist(e[a],t)},B.prototype.te=function(t){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return(r=this)._te.apply(r,[t,this.locale,this.messages].concat(n));var r},Object.defineProperties(B.prototype,G),B.install=c,B.version="6.0.0-alpha.2","undefined"!=typeof window&&window.Vue&&window.Vue.use(B),B});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.VueI18n=n()}(this,function(){"use strict";function t(t,n){"undefined"!=typeof console&&(console.warn("[vue-i18n] "+t),n&&console.warn(n.stack))}function n(t,n){return k.call(t,n)}function e(t){return null!==t&&"object"==typeof t}function r(t){return j.call(t)===A}function i(t){if(t.name)return t.name;var n=/^\s*function\s*([^\(]*)/im.exec(t.toString());return n?n[1]:""}function o(t){var n=j.call(t).slice(8,-1);return"Object"!==n&&"Error"!==n||!t.constructor?n:i(t.constructor)}function a(t){if(null===t)return"null";var n=typeof t;return"object"===n?o(t):n}function s(t){return null===t||void 0===t}function c(){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 l(t){return t?t>1?1:0:1}function u(t,n){return t=Math.abs(t),2===n?l(t):t?Math.min(t,2):0}function f(t,n){if(!t&&"string"!=typeof t)return null;var e=t.split("|");return n=u(n,e.length),e[n]?e[n].trim():t}function h(t){b=t;b.version&&Number(b.version.split(".")[0])||-1;h.installed=!0,b.mixin(L),V(b)}function p(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];return e=1===e.length&&"object"==typeof e[0]?e[0]:{},e&&e.hasOwnProperty||(e={}),t.replace(I,function(r,i,o,a){var c;return"{"===t[a-1]&&"}"===t[a+r.length]?o:(c=n(e,o)?e[o]:r,s(c)?"":c)})}function v(t){return G.test(t)}function _(t){var n=t.charCodeAt(0),e=t.charCodeAt(t.length-1);return n!==e||34!==n&&39!==n?t:t.slice(1,-1)}function m(t){if(void 0===t||null===t)return"eof";var n=t.charCodeAt(0);switch(n){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 n>=97&&n<=122||n>=65&&n<=90?"ident":n>=49&&n<=57?"number":"else"}function g(t){var n=t.trim();return("0"!==t.charAt(0)||!isNaN(t))&&(v(n)?_(n):"*"+n)}function d(t){function n(){var n=t[u+1];if(f===U&&"'"===n||f===z&&'"'===n)return u++,i="\\"+n,p[F](),!0}var e,r,i,o,a,s,c,l=[],u=-1,f=C,h=0,p=[];for(p[M]=function(){void 0!==r&&(l.push(r),r=void 0)},p[F]=function(){void 0===r?r=i:r+=i},p[R]=function(){p[F](),h++},p[S]=function(){if(h>0)h--,f=D,p[F]();else{if(h=0,r=g(r),r===!1)return!1;p[M]()}};null!==f;)if(u++,e=t[u],"\\"!==e||!n()){if(o=m(e),c=B[f],a=c[o]||c.else||q,a===q)return;if(f=a[0],s=p[a[1]],s&&(i=a[2],i=void 0===i?e:i,s()===!1))return;if(f===Z)return l}}function y(t){var n=E[t];return n||(n=d(t),n&&(E[t]=n)),n||[]}function $(t){if(null===t||void 0===t)return!0;if(Array.isArray(t)){if(t.length>0)return!1;if(0===t.length)return!0}else if(r(t))for(var e in t)if(n(t,e))return!1;return!0}function w(t,n){if(!e(t))return null;var r=y(n);if($(r))return null;for(var i=r.length,o=null,a=t,s=0;s<i;){var c=a[r[s]];if(void 0===c){a=null;break}a=c,s++}return o=a}var b,k=Object.prototype.hasOwnProperty,j=Object.prototype.toString,A="[object Object]",L={computed:{$t:function(){var t=this;if(!this.$i18n)throw Error("Failed in $t due to not find VueI18n instance");var n=this.$i18n.locale,e=this.$i18n.messages;return function(r){for(var i=[],o=arguments.length-1;o-- >0;)i[o]=arguments[o+1];return(a=t.$i18n)._t.apply(a,[r,n,e,t].concat(i));var a}},$tc:function(){var t=this;if(!this.$i18n)throw Error("Failed in $tc due to not find VueI18n instance");var n=this.$i18n.locale,e=this.$i18n.messages;return function(r,i){for(var o=[],a=arguments.length-2;a-- >0;)o[a]=arguments[a+2];return(s=t.$i18n)._tc.apply(s,[r,n,e,t,i].concat(o));var s}},$te:function(){var t=this;if(!this.$i18n)throw Error("Failed in $te due to not find VueI18n instance");var n=this.$i18n.locale,e=this.$i18n.messages;return function(r){for(var i=[],o=arguments.length-1;o-- >0;)i[o]=arguments[o+1];return(a=t.$i18n)._te.apply(a,[r,n,e].concat(i));var a}}},beforeCreate:function(){var t=this.$options;t.i18n?"VueI18n"===a(t.i18n)?this.$i18n=t.i18n:r(t.i18n)&&(this.$root&&this.$root.$i18n&&"VueI18n"===a(this.$root.$i18n)&&(t.i18n.root=this.$root.$i18n),this.$i18n=new H(t.i18n),t.i18n.sync&&(this._localeWatcher=this.$i18n.watchLocale())):this.$root&&this.$root.$i18n&&"VueI18n"===a(this.$root.$i18n)&&(this.$i18n=this.$root.$i18n)},destroyed:function(){this._localeWatcher&&(this.$i18n.unwatchLocale(),delete this._localeWatcher),this.$i18n=null}},V=function(t){var n=t.config.optionMergeStrategies;n&&(n.i18n=function(n,e){var r=Object.create(null);if(!e)return n;if(!n)return e;if(!e&!n)return r;t.util.extend(r,n);for(var i in e)r[i]=e[i];return r})},O=function(t){void 0===t&&(t={}),this._options=t},x={options:{}};x.options.get=function(){return this._options},O.prototype.format=function(t){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return p.apply(void 0,[t].concat(n))},Object.defineProperties(O.prototype,x);var I=/(%|)\{([0-9a-zA-Z_]+)\}/g,E=Object.create(null),F=0,M=1,R=2,S=3,C=0,P=1,N=2,W=3,D=4,U=5,z=6,Z=7,q=8,B=[];B[C]={ws:[C],ident:[W,F],"[":[D],eof:[Z]},B[P]={ws:[P],".":[N],"[":[D],eof:[Z]},B[N]={ws:[N],ident:[W,F],0:[W,F],number:[W,F]},B[W]={ident:[W,F],0:[W,F],number:[W,F],ws:[P,M],".":[N,M],"[":[D,M],eof:[Z,M]},B[D]={"'":[U,F],'"':[z,F],"[":[D,R],"]":[P,S],eof:q,else:[D,F]},B[U]={"'":[D,F],eof:q,else:[U,F]},B[z]={'"':[D,F],eof:q,else:[z,F]};var G=/^\s?(true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/,H=function(t){void 0===t&&(t={});var n=t.locale||"en-US",e=t.messages||{};this._vm=null,this._fallbackLocale=t.fallbackLocale||"en-US",this._formatter=t.formatter||new O,this._missing=t.missing,this._root=t.root||null,this._sync=t.sync||!1,this._fallbackRoot=t.fallbackRoot||!1,this._exist=function(t,n){return!(!t||!n)&&!s(w(t,n))},this._resetVM({locale:n,messages:e})},J={vm:{},messages:{},locale:{},fallbackLocale:{},missing:{},formatter:{}};return H.prototype._resetVM=function(t){var n=b.config.silent;b.config.silent=!0,this._vm=new b({data:t}),b.config.silent=n},H.prototype.watchLocale=function(){if(!this._sync||!this._root)return null;var t=this._vm;return this._watcher=this._root.vm.$watch("locale",function(n){t.$set(t,"locale",n)},{immediate:!0}),this._watcher},H.prototype.unwatchLocale=function(){return!(!this._sync||!this._watcher)&&(this._watcher&&(this._watcher(),delete this._watcher),!0)},J.vm.get=function(){return this._vm},J.messages.get=function(){return this._vm.$data.messages},J.messages.set=function(t){this._vm.$set(this._vm,"messages",t)},J.locale.get=function(){return this._vm.$data.locale},J.locale.set=function(t){this._vm.$set(this._vm,"locale",t)},J.fallbackLocale.get=function(){return this._fallbackLocale},J.fallbackLocale.set=function(t){this._fallbackLocale=t},J.missing.get=function(){return this._missing},J.missing.set=function(t){this._missing=t},J.formatter.get=function(){return this._formatter},J.formatter.set=function(t){this._formatter=t},H.prototype._warnDefault=function(t,n,e,r){return s(e)?(this.missing&&this.missing.apply(null,[t,n,r]),n):e},H.prototype._isFallbackRoot=function(t){return!t&&!s(this._root)&&this._fallbackRoot},H.prototype._interpolate=function(n,e,r){var i=this;if(!n)return null;var o=w(n,e);if(Array.isArray(o))return o;if(s(o)&&(o=n[e]),s(o))return null;if("string"!=typeof o)return t("Value of key '"+e+"' is not a string!"),null;if(o.indexOf("@:")>=0){var a=o.match(/(@:[\w|.]+)/g);for(var c in a){var l=a[c],u=l.substr(2),f=i._interpolate(n,u,r);o=o.replace(l,f)}}return r?this._format(o,r):o},H.prototype._format=function(t){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return(r=this._formatter).format.apply(r,[t].concat(n));var r},H.prototype._translate=function(t,n,e,r,i){var o=null;return o=this._interpolate(t[n],r,i),s(o)?(o=this._interpolate(t[e],r,i),s(o)?null:o):o},H.prototype._t=function(t,n,e,r){for(var i=[],o=arguments.length-4;o-- >0;)i[o]=arguments[o+4];if(!t)return"";var a=c.apply(void 0,i),s=a.locale||n,l=this._translate(e,s,this.fallbackLocale,t,a.params);if(this._isFallbackRoot(l)){if(!this._root)throw Error("unexpected error");return(u=this._root).t.apply(u,[t].concat(i))}return this._warnDefault(s,t,l,r);var u},H.prototype.t=function(t){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return(r=this)._t.apply(r,[t,this.locale,this.messages,null].concat(n));var r},H.prototype._tc=function(t,n,e,r,i){for(var o=[],a=arguments.length-5;a-- >0;)o[a]=arguments[a+5];return t?void 0!==i?f((s=this)._t.apply(s,[t,n,e,r].concat(o)),i):(c=this)._t.apply(c,[t,n,e,r].concat(o)):"";var s,c},H.prototype.tc=function(t,n){for(var e=[],r=arguments.length-2;r-- >0;)e[r]=arguments[r+2];return(i=this)._tc.apply(i,[t,this.locale,this.messages,null,n].concat(e));var i},H.prototype._te=function(t,n,e){for(var r=[],i=arguments.length-3;i-- >0;)r[i]=arguments[i+3];var o=c.apply(void 0,r).locale||n;return this._exist(e[o],t)},H.prototype.te=function(t){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return(r=this)._te.apply(r,[t,this.locale,this.messages].concat(n));var r},Object.defineProperties(H.prototype,J),H.install=h,H.version="6.0.0-alpha.3","undefined"!=typeof window&&window.Vue&&window.Vue.use(H),H});
{
"name": "vue-i18n",
"description": "Internationalization plugin for Vue.js",
"version": "6.0.0-alpha.2",
"version": "6.0.0-alpha.3",
"author": {

@@ -6,0 +6,0 @@ "name": "kazuya kawaguchi",

@@ -10,2 +10,5 @@ # vue-i18n

## :warning: Release versions
- dev version: v6.0.0-alpah~
- stable version: v5.0.3

@@ -12,0 +15,0 @@ ## :book: Documentation

@@ -1,2 +0,4 @@

export default function (Vue) {
/* @flow */
export default function (Vue: typeof Vue) {
const strats = Vue.config.optionMergeStrategies

@@ -3,0 +5,0 @@ if (strats) {

@@ -17,2 +17,3 @@ /* @flow */

_root: ?I18n
_sync: ?boolean
_fallbackRoot: boolean

@@ -22,2 +23,3 @@ _fallbackLocale: string

_exist: Function
_watcher: any

@@ -32,2 +34,3 @@ constructor (options: I18nOptions = {}) {

this._root = options.root || null
this._sync = options.sync || false
this._fallbackRoot = options.fallbackRoot || false

@@ -50,2 +53,22 @@

watchLocale (): any {
if (!this._sync || !this._root) { return null }
const target: any = this._vm
this._watcher = this._root.vm.$watch('locale', (val) => {
target.$set(target, 'locale', val)
}, { immediate: true })
return this._watcher
}
unwatchLocale (): boolean {
if (!this._sync || !this._watcher) { return false }
if (this._watcher) {
this._watcher()
delete this._watcher
}
return true
}
get vm (): any { return this._vm }
get messages (): Messages { return this._vm.$data.messages }

@@ -52,0 +75,0 @@ set messages (messages: Messages): void { this._vm.$set(this._vm, 'messages', messages) }

/* @flow */
import VueI18n from './index'
import { typeName, isPlainObject, warn } from './util'

@@ -8,3 +9,6 @@ export default {

$t () {
// HACK: add dependency tracking !!
if (!this.$i18n) {
throw Error(`Failed in $t due to not find VueI18n instance`)
}
// add dependency tracking !!
const locale: string = this.$i18n.locale

@@ -18,3 +22,6 @@ const messages: Messages = this.$i18n.messages

$tc () {
// HACK: add dependency tracking !!
if (!this.$i18n) {
throw Error(`Failed in $tc due to not find VueI18n instance`)
}
// add dependency tracking !!
const locale: string = this.$i18n.locale

@@ -28,3 +35,6 @@ const messages: Messages = this.$i18n.messages

$te () {
// HACK: add dependency tracking !!
if (!this.$i18n) {
throw Error(`Failed in $te due to not find VueI18n instance`)
}
// add dependency tracking !!
const locale: string = this.$i18n.locale

@@ -41,12 +51,19 @@ const messages: Messages = this.$i18n.messages

if (options.i18n) {
if (options.i18n instanceof VueI18n) {
if (typeName(options.i18n) === 'VueI18n') {
this.$i18n = options.i18n
} else {
} else if (isPlainObject(options.i18n)) {
// component local i18n
if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
if (this.$root && this.$root.$i18n && typeName(this.$root.$i18n) === 'VueI18n') {
options.i18n.root = this.$root.$i18n
}
this.$i18n = new VueI18n(options.i18n)
if (options.i18n.sync) {
this._localeWatcher = this.$i18n.watchLocale()
}
} else {
if (process.env.NODE_ENV !== 'production') {
warn(`Cannot be interpreted 'i18n' option.`)
}
}
} else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
} else if (this.$root && this.$root.$i18n && typeName(this.$root.$i18n) === 'VueI18n') {
// root i18n

@@ -57,5 +74,10 @@ this.$i18n = this.$root.$i18n

beforeDestroy () {
destroyed () {
if (this._localeWatcher) {
this.$i18n.unwatchLocale()
delete this._localeWatcher
}
this.$i18n = null
}
}

@@ -45,2 +45,23 @@ /* @flow */

function funcName (f: Function): string {
if (f.name) { return f.name }
const match = /^\s*function\s*([^\(]*)/im.exec(f.toString())
return match ? match[1] : ''
}
function ctorName (obj: any): string {
const str = toString.call(obj).slice(8, -1)
if ((str === 'Object' || str === 'Error') && obj.constructor) {
return funcName(obj.constructor)
}
return str
}
export function typeName (val: mixed): string {
if (val === null) { return 'null' }
const type: string = typeof val
if (type === 'object') { return ctorName(val) }
return type
}
export function isNull (val: mixed): boolean {

@@ -47,0 +68,0 @@ return val === null || val === undefined

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc