Comparing version 2.0.0 to 2.1.0
@@ -5,3 +5,3 @@ { | ||
"description": "Internationalization plugin of Vue.js", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"homepage": "https://github.com/kazupon/vue-i18n", | ||
@@ -8,0 +8,0 @@ "authors": [ |
@@ -0,1 +1,5 @@ | ||
# v2.1.0 / 2015-07-03 | ||
* Add global local language setting with `Vue.config.lang` | ||
# v2.0.0 / 2015-06-29 | ||
@@ -2,0 +6,0 @@ |
{ | ||
"name": "vue-i18n", | ||
"repo": "kazupon/vue-i18n", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Internationalization plugin of Vue.js", | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
/** | ||
* vue-i18n v2.0.0 | ||
* vue-i18n v2.1.0 | ||
* (c) 2015 kazuya kawaguchi | ||
@@ -67,3 +67,3 @@ * Released under the MIT License. | ||
var format = __webpack_require__(1) | ||
var extend = __webpack_require__(1) | ||
@@ -90,6 +90,59 @@ | ||
defineConfig(Vue.config, lang) | ||
extend(Vue, locales) | ||
} | ||
/** | ||
* defineConfig | ||
* | ||
* This function define `lang` property to `Vue.config`. | ||
* | ||
* @param {Object} config | ||
* @param {String} lang | ||
* @private | ||
*/ | ||
function defineConfig (config, lang) { | ||
Object.defineProperty(config, 'lang', { | ||
get: function () { return lang }, | ||
set: function (val) { lang = val } | ||
}) | ||
} | ||
/***/ }, | ||
/* 1 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/** | ||
* Import(s) | ||
*/ | ||
var format = __webpack_require__(2) | ||
/** | ||
* Export(s) | ||
*/ | ||
module.exports = extend | ||
/** | ||
* extend | ||
* | ||
* @param {Vue} Vue | ||
* @param {Object} locales | ||
* @return {Vue} | ||
*/ | ||
function extend (Vue, locales) { | ||
var path = Vue.parsers.path | ||
var util = Vue.util | ||
function getVal (path, key, lang, args) { | ||
var value = key | ||
try { | ||
var val = path.get(locales[lang], key) | ||
var val = path.get(locales[lang], key) || locales[lang][key] | ||
value = (args ? format(val, args) : val) || key | ||
@@ -102,5 +155,2 @@ } catch (e) { | ||
var path = Vue.parsers.path | ||
var util = Vue.util | ||
Vue.prototype.$t = function (key) { | ||
@@ -110,3 +160,3 @@ if (!key) { return '' } | ||
var args = null | ||
var language = lang | ||
var language = Vue.config.lang | ||
if (arguments.length === 2) { | ||
@@ -129,2 +179,4 @@ if (util.isObject(arguments[1]) || util.isArray(arguments[1])) { | ||
} | ||
return Vue | ||
} | ||
@@ -134,3 +186,3 @@ | ||
/***/ }, | ||
/* 1 */ | ||
/* 2 */ | ||
/***/ function(module, exports) { | ||
@@ -137,0 +189,0 @@ |
/** | ||
* vue-i18n v2.0.0 | ||
* vue-i18n v2.1.0 | ||
* (c) 2015 kazuya kawaguchi | ||
@@ -7,2 +7,2 @@ * Released under the MIT License. | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):"object"==typeof exports?exports["vue-i18n"]=e():t["vue-i18n"]=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){function n(t,e){function r(t,e,r,n){var a=e;try{var s=t.get(u[r],e);a=(n?o(s,n):s)||e}catch(i){a=e}return a}e=e||{};var n=e.lang||"en",u=e.locales||{},a=t.parsers.path,s=t.util;t.prototype.$t=function(t){if(!t)return"";var e=null,o=n;return 2===arguments.length?s.isObject(arguments[1])||s.isArray(arguments[1])?e=arguments[1]:"string"==typeof arguments[1]&&(o=arguments[1]):3===arguments.length&&("string"==typeof arguments[1]&&(o=arguments[1]),(s.isObject(arguments[2])||s.isArray(arguments[2]))&&(e=arguments[2])),r(a,t,o,e)}}var o=r(1);t.exports=n},function(t,e){function r(t){var e;return e=2===arguments.length&&"object"==typeof arguments[1]?arguments[1]:n.call(arguments,1),e&&e.hasOwnProperty||(e={}),t.replace(o,function(r,n,o){var u;return"{"===t[o-1]&&"}"===t[o+r.length]?n:(u=e.hasOwnProperty(n)?e[n]:null,null===u||void 0===u?"":u)})}var n=Array.prototype.slice,o=/\{([0-9a-zA-Z]+)\}/g;t.exports=r}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):"object"==typeof exports?exports["vue-i18n"]=e():t["vue-i18n"]=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){function r(t,e){e=e||{};var n=e.lang||"en",r=e.locales||{};o(t.config,n),u(t,r)}function o(t,e){Object.defineProperty(t,"lang",{get:function(){return e},set:function(t){e=t}})}var u=n(1);t.exports=r},function(t,e,n){function r(t,e){function n(t,n,r,u){var a=n;try{var s=t.get(e[r],n)||e[r][n];a=(u?o(s,u):s)||n}catch(i){a=n}return a}var r=t.parsers.path,u=t.util;return t.prototype.$t=function(e){if(!e)return"";var o=null,a=t.config.lang;return 2===arguments.length?u.isObject(arguments[1])||u.isArray(arguments[1])?o=arguments[1]:"string"==typeof arguments[1]&&(a=arguments[1]):3===arguments.length&&("string"==typeof arguments[1]&&(a=arguments[1]),(u.isObject(arguments[2])||u.isArray(arguments[2]))&&(o=arguments[2])),n(r,e,a,o)},t}var o=n(2);t.exports=r},function(t,e){function n(t){var e;return e=2===arguments.length&&"object"==typeof arguments[1]?arguments[1]:r.call(arguments,1),e&&e.hasOwnProperty||(e={}),t.replace(o,function(n,r,o){var u;return"{"===t[o-1]&&"}"===t[o+n.length]?r:(u=e.hasOwnProperty(r)?e[r]:null,null===u||void 0===u?"":u)})}var r=Array.prototype.slice,o=/\{([0-9a-zA-Z]+)\}/g;t.exports=n}])}); |
52
index.js
@@ -5,3 +5,3 @@ /** | ||
var format = require('./lib/format') | ||
var extend = require('./lib/extend') | ||
@@ -28,38 +28,22 @@ | ||
function getVal (path, key, lang, args) { | ||
var value = key | ||
try { | ||
var val = path.get(locales[lang], key) | ||
value = (args ? format(val, args) : val) || key | ||
} catch (e) { | ||
value = key | ||
} | ||
return value | ||
} | ||
defineConfig(Vue.config, lang) | ||
extend(Vue, locales) | ||
} | ||
var path = Vue.parsers.path | ||
var util = Vue.util | ||
Vue.prototype.$t = function (key) { | ||
if (!key) { return '' } | ||
/** | ||
* defineConfig | ||
* | ||
* This function define `lang` property to `Vue.config`. | ||
* | ||
* @param {Object} config | ||
* @param {String} lang | ||
* @private | ||
*/ | ||
var args = null | ||
var language = lang | ||
if (arguments.length === 2) { | ||
if (util.isObject(arguments[1]) || util.isArray(arguments[1])) { | ||
args = arguments[1] | ||
} else if (typeof arguments[1] === 'string') { | ||
language = arguments[1] | ||
} | ||
} else if (arguments.length === 3) { | ||
if (typeof arguments[1] === 'string') { | ||
language = arguments[1] | ||
} | ||
if (util.isObject(arguments[2]) || util.isArray(arguments[2])) { | ||
args = arguments[2] | ||
} | ||
} | ||
return getVal(path, key, language, args) | ||
} | ||
function defineConfig (config, lang) { | ||
Object.defineProperty(config, 'lang', { | ||
get: function () { return lang }, | ||
set: function (val) { lang = val } | ||
}) | ||
} |
{ | ||
"name": "vue-i18n", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Internationalization plugin of Vue.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -152,3 +152,3 @@ # vue-i18n | ||
## #$t(keypath, [lang], [arguments]) | ||
## $t(keypath, [lang], [arguments]) | ||
- keypath: `String` **required** | ||
@@ -158,5 +158,43 @@ - lang: `String` **optional** | ||
Translate the locale of `keypath`. if specify `lang`, translate the locale of `lang`. if you are specified list formatting locale or named formatting of `keypath`, also you must specify `arguments`. | ||
Translate the locale of `keypath`. If you specified `lang`, translate the locale of `lang`. If you specified `keypath` of list / named formatting local, you must specify `arguments` too. For `arguments` more details see [Formatting](https://github.com/kazupon/vue-i18n#formatting). | ||
# Options | ||
## Plugin options | ||
```javascript | ||
Vue.use(plugin, { | ||
lang: 'en', | ||
locals: { | ||
en: { | ||
... | ||
}, | ||
... | ||
ja: { | ||
... | ||
} | ||
} | ||
}) | ||
``` | ||
### lang | ||
Specify translate the language code. | ||
If you abbreviated the `lang` option, translate as well as 'en' language code option (default: 'en'). | ||
### locals | ||
Specify translate some local dictionary. | ||
If you abbreviated the `locales` option, set the empty local dictionary. | ||
# Configrations | ||
## Vue.config.lang | ||
Get or set a global translation language code. Default by `en` string value. You can change the language of the global level dynamic translation in your application. | ||
When specified with `lang` plugins option at `Vue.use`, `Vue.config.lang` is set that value. | ||
# Contributing | ||
@@ -167,3 +205,3 @@ - Fork it ! | ||
- Push to the branch: `git push origin my-new-topic` | ||
- Submit a pull request to `dev` branch of `vuejs/vue-validator` repository ! | ||
- Submit a pull request to `dev` branch of `kazupon/vue-i18n` repository ! | ||
@@ -170,0 +208,0 @@ |
@@ -19,3 +19,5 @@ /** | ||
} | ||
} | ||
}, | ||
'hello world': 'Hello World', | ||
'Hello {0}': 'Hello {0}' | ||
}, | ||
@@ -78,2 +80,20 @@ ja: { | ||
}) | ||
describe('sentence fragment', function () { | ||
it('should translate fragment', function () { | ||
var vm = new Vue() | ||
expect(vm.$t('hello world')).to.be.eql('Hello World') | ||
}) | ||
it('should return replaced string if available', function () { | ||
var vm = new Vue() | ||
expect(vm.$t('Hello {0}', ['kazupon'])) | ||
.to.be.eql('Hello kazupon') | ||
}) | ||
it('should return key if unavailable', function () { | ||
var vm = new Vue() | ||
expect(vm.$t('Hello')).to.be.eql('Hello') | ||
}) | ||
}) | ||
}) | ||
@@ -175,2 +195,24 @@ | ||
}) | ||
describe('global lang config', function () { | ||
var vm | ||
beforeEach(function () { | ||
vm = new Vue() | ||
}) | ||
describe('ja', function () { | ||
it('should translate with japanese', function () { | ||
Vue.config.lang = 'ja' | ||
expect(vm.$t('message.hello')).to.be.eql(locales.ja.message.hello) | ||
}) | ||
describe('en', function () { | ||
it('should translate with english', function () { | ||
Vue.config.lang = 'en' | ||
expect(vm.$t('message.hello')).to.be.eql(locales.en.message.hello) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
230248
43
8535
218