Skip to content

Commit

Permalink
✨ release(patch): v6.0.0-alpha.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Mar 8, 2017
1 parent 757b439 commit 8f04abc
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 30 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<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>
# [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)

Expand Down
91 changes: 78 additions & 13 deletions dist/vue-i18n.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue-i18n v6.0.0-alpha.2
* vue-i18n v6.0.0-alpha.3
* (c) 2017 kazuya kawaguchi
* Released under the MIT License.
*/
Expand Down Expand Up @@ -37,6 +37,27 @@ function isPlainObject (obj) {
return toString.call(obj) === OBJECT_STRING
}

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) {
return val === null || val === undefined
}
Expand Down Expand Up @@ -97,7 +118,10 @@ var mixin = {
$t: function $t () {
var this$1 = this;

// 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;
var messages = this.$i18n.messages;
return function (key) {
Expand All @@ -112,7 +136,10 @@ var mixin = {
$tc: function $tc () {
var this$1 = this;

// 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;
var messages = this.$i18n.messages;
return function (key, choice) {
Expand All @@ -127,7 +154,10 @@ var mixin = {
$te: function $te () {
var this$1 = this;

// 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;
var messages = this.$i18n.messages;
return function (key) {
Expand All @@ -143,26 +173,40 @@ var mixin = {
beforeCreate: function beforeCreate () {
var options = this.$options;
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
this.$i18n = this.$root.$i18n;
}
},

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

this.$i18n = null;
}
};

/* */

var Asset = function (Vue) {
var strats = Vue.config.optionMergeStrategies;
if (strats) {
Expand Down Expand Up @@ -611,6 +655,7 @@ var VueI18n = function VueI18n (options) {
this._formatter = options.formatter || new BaseFormatter();
this._missing = options.missing;
this._root = options.root || null;
this._sync = options.sync || false;
this._fallbackRoot = options.fallbackRoot || false;

this._exist = function (message, key) {
Expand All @@ -621,7 +666,7 @@ var VueI18n = function VueI18n (options) {
this._resetVM({ locale: locale, messages: messages });
};

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

VueI18n.prototype._resetVM = function _resetVM (data) {
var silent = Vue.config.silent;
Expand All @@ -630,6 +675,26 @@ VueI18n.prototype._resetVM = function _resetVM (data) {
Vue.config.silent = silent;
};

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 };
prototypeAccessors.messages.set = function (messages) { this._vm.$set(this._vm, 'messages', messages); };

Expand Down Expand Up @@ -750,9 +815,9 @@ VueI18n.prototype.t = function t (key) {

return (ref = this)._t.apply(ref, [ key, this.locale, this.messages, null ].concat( args ))
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;
while ( len-- > 0 ) args[ len ] = arguments[ len + 5 ];

Expand Down Expand Up @@ -786,7 +851,7 @@ VueI18n.prototype.te = function te (key) {
var args = [], len = arguments.length - 1;
while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];

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;
};

Expand Down
93 changes: 79 additions & 14 deletions dist/vue-i18n.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue-i18n v6.0.0-alpha.2
* vue-i18n v6.0.0-alpha.3
* (c) 2017 kazuya kawaguchi
* Released under the MIT License.
*/
Expand Down Expand Up @@ -41,6 +41,27 @@ function isPlainObject (obj) {
return toString.call(obj) === OBJECT_STRING
}

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) {
return val === null || val === undefined
}
Expand Down Expand Up @@ -101,7 +122,10 @@ var mixin = {
$t: function $t () {
var this$1 = this;

// 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;
var messages = this.$i18n.messages;
return function (key) {
Expand All @@ -116,7 +140,10 @@ var mixin = {
$tc: function $tc () {
var this$1 = this;

// 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;
var messages = this.$i18n.messages;
return function (key, choice) {
Expand All @@ -131,7 +158,10 @@ var mixin = {
$te: function $te () {
var this$1 = this;

// 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;
var messages = this.$i18n.messages;
return function (key) {
Expand All @@ -147,26 +177,40 @@ var mixin = {
beforeCreate: function beforeCreate () {
var options = this.$options;
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
this.$i18n = this.$root.$i18n;
}
},

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

this.$i18n = null;
}
};

/* */

var Asset = function (Vue) {
var strats = Vue.config.optionMergeStrategies;
if (strats) {
Expand Down Expand Up @@ -615,6 +659,7 @@ var VueI18n = function VueI18n (options) {
this._formatter = options.formatter || new BaseFormatter();
this._missing = options.missing;
this._root = options.root || null;
this._sync = options.sync || false;
this._fallbackRoot = options.fallbackRoot || false;

this._exist = function (message, key) {
Expand All @@ -625,7 +670,7 @@ var VueI18n = function VueI18n (options) {
this._resetVM({ locale: locale, messages: messages });
};

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

VueI18n.prototype._resetVM = function _resetVM (data) {
var silent = Vue.config.silent;
Expand All @@ -634,6 +679,26 @@ VueI18n.prototype._resetVM = function _resetVM (data) {
Vue.config.silent = silent;
};

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 };
prototypeAccessors.messages.set = function (messages) { this._vm.$set(this._vm, 'messages', messages); };

Expand Down Expand Up @@ -754,9 +819,9 @@ VueI18n.prototype.t = function t (key) {

return (ref = this)._t.apply(ref, [ key, this.locale, this.messages, null ].concat( args ))
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;
while ( len-- > 0 ) args[ len ] = arguments[ len + 5 ];

Expand Down Expand Up @@ -790,14 +855,14 @@ VueI18n.prototype.te = function te (key) {
var args = [], len = arguments.length - 1;
while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];

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;
};

Object.defineProperties( VueI18n.prototype, prototypeAccessors );

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

if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(VueI18n);
Expand Down
Loading

0 comments on commit 8f04abc

Please sign in to comment.