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 1.1.1 to 2.0.0

CHANGELOG.md

2

bower.json

@@ -5,3 +5,3 @@ {

"description": "Internationalization plugin of Vue.js",
"version": "1.1.1",
"version": "2.0.0",
"homepage": "https://github.com/kazupon/vue-i18n",

@@ -8,0 +8,0 @@ "authors": [

{
"name": "vue-i18n",
"repo": "kazupon/vue-i18n",
"version": "1.1.1",
"version": "2.0.0",
"description": "Internationalization plugin of Vue.js",
"license": "MIT",
"keywords": [
"Vue.js",
"i18n",
"internationalization",
"plugin"
],
"dependencies": {},
"development": {},
"scripts": [
"lib/format.js",
"index.js"
],
"main": "index.js"
"main": "index.js",
"license": "MIT"
}
/**
* vue-i18n v1.1.1
* vue-i18n v2.0.0
* (c) 2015 kazuya kawaguchi

@@ -87,3 +87,3 @@ * Released under the MIT License.

var lang = opts.lang || 'en'
var locales = opts.locales || opts.resources || {}
var locales = opts.locales || {}

@@ -101,61 +101,27 @@ function getVal (path, key, lang, args) {

// `$t` method (for Vue 0.11.4 later)
try {
var path = Vue.parsers.path
var util = Vue.util
var path = Vue.parsers.path
var util = Vue.util
Vue.prototype.$t = function (key) {
if (!key) { return '' }
Vue.prototype.$t = function (key) {
if (!key) { return '' }
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]
}
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]
}
return getVal(path, key, language, args)
} 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]
}
}
} catch (e) {
Vue.utils.warn('not support $t in this Vue version')
}
// 't' function
Vue.t = function (key) {
var ret = key || ''
var locale = locales[lang]
if (key && locale) {
var namespaces = key.split('.')
for (var i = 0; i < namespaces.length; i++) {
locale = locale[namespaces[i]]
if (!locale) {
ret = key
break
} else {
ret = locale
}
}
}
return ret
return getVal(path, key, language, args)
}
// 'v-t' directive
Vue.directive('t', {
isLiteral: true,
bind: function () {
if (this.el.nodeType !== 1) { return }
this.el.textContent = Vue.t(this.expression)
}
})
}

@@ -166,3 +132,3 @@

/* 1 */
/***/ function(module, exports, __webpack_require__) {
/***/ function(module, exports) {

@@ -169,0 +135,0 @@ /**

/**
* vue-i18n v1.1.1
* vue-i18n v2.0.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 u=e;try{var a=t.get(s[r],e);u=(n?o(a,n):a)||e}catch(i){u=e}return u}e=e||{};var n=e.lang||"en",s=e.locales||e.resources||{};try{var u=t.parsers.path,a=t.util;t.prototype.$t=function(t){if(!t)return"";var e=null,o=n;return 2===arguments.length?a.isObject(arguments[1])||a.isArray(arguments[1])?e=arguments[1]:"string"==typeof arguments[1]&&(o=arguments[1]):3===arguments.length&&("string"==typeof arguments[1]&&(o=arguments[1]),(a.isObject(arguments[2])||a.isArray(arguments[2]))&&(e=arguments[2])),r(u,t,o,e)}}catch(i){t.utils.warn("not support $t in this Vue version")}t.t=function(t){var e=t||"",r=s[n];if(t&&r)for(var o=t.split("."),u=0;u<o.length;u++){if(r=r[o[u]],!r){e=t;break}e=r}return e},t.directive("t",{isLiteral:!0,bind:function(){1===this.el.nodeType&&(this.el.textContent=t.t(this.expression))}})}var o=r(1);t.exports=n},function(t,e,r){function n(t){var e;return e=2===arguments.length&&"object"==typeof arguments[1]?arguments[1]:o.call(arguments,1),e&&e.hasOwnProperty||(e={}),t.replace(s,function(r,n,o){var s;return"{"===t[o-1]&&"}"===t[o+r.length]?n:(s=e.hasOwnProperty(n)?e[n]:null,null===s||void 0===s?"":s)})}var o=Array.prototype.slice,s=/\{([0-9a-zA-Z]+)\}/g;t.exports=n}])});
!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}])});

@@ -6,17 +6,4 @@ {

"description": "duo vue-i18n example",
"license": "MIT",
"keywords": [
"Vue.js",
"i18n",
"internationalization"
],
"dependencies": {
"kazupon/vue-i18n": "*",
"yyx990803/vue": "^0.11.0-rc"
},
"development": {},
"scripts": [
"index.js"
],
"main": "index.js"
"main": "index.js",
"license": "MIT"
}

@@ -28,3 +28,1 @@ var Vue = require('vue')

})
vm.$t('hello.foo')

@@ -25,3 +25,3 @@ /**

var lang = opts.lang || 'en'
var locales = opts.locales || opts.resources || {}
var locales = opts.locales || {}

@@ -39,61 +39,27 @@ function getVal (path, key, lang, args) {

// `$t` method (for Vue 0.11.4 later)
try {
var path = Vue.parsers.path
var util = Vue.util
var path = Vue.parsers.path
var util = Vue.util
Vue.prototype.$t = function (key) {
if (!key) { return '' }
Vue.prototype.$t = function (key) {
if (!key) { return '' }
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]
}
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]
}
return getVal(path, key, language, args)
} 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]
}
}
} catch (e) {
Vue.utils.warn('not support $t in this Vue version')
}
// 't' function
Vue.t = function (key) {
var ret = key || ''
var locale = locales[lang]
if (key && locale) {
var namespaces = key.split('.')
for (var i = 0; i < namespaces.length; i++) {
locale = locale[namespaces[i]]
if (!locale) {
ret = key
break
} else {
ret = locale
}
}
}
return ret
return getVal(path, key, language, args)
}
// 'v-t' directive
Vue.directive('t', {
isLiteral: true,
bind: function () {
if (this.el.nodeType !== 1) { return }
this.el.textContent = Vue.t(this.expression)
}
})
}
{
"name": "vue-i18n",
"version": "1.1.1",
"version": "2.0.0",
"description": "Internationalization plugin of Vue.js",

@@ -26,2 +26,3 @@ "main": "index.js",

"devDependencies": {
"commander": "^2.8.1",
"expect.js": "^0.3.1",

@@ -43,5 +44,5 @@ "jshint": "^2.5.0",

"semi": "^3.1.1",
"vue": "~0.11.4",
"vue": "^0.12.0",
"webpack": "^1.4.13"
}
}

@@ -6,3 +6,2 @@ # vue-i18n

[![NPM version](https://badge.fury.io/js/vue-i18n.svg)](http://badge.fury.io/js/vue-i18n)
[![Dependency Status](https://david-dm.org/kazupon/vue-i18n.svg)](https://david-dm.org/kazupon/vue-i18n)
[![Sauce Test Status](https://saucelabs.com/buildstatus/vue-i18n)](https://saucelabs.com/u/vue-i18n)

@@ -14,4 +13,4 @@

# Requirments
- works with Vue.js ^`0.10.4`
# Requirements
- works with Vue.js ^`0.12.0`

@@ -21,6 +20,6 @@

## component
## npm
```shell
$ component install kazupon/vue-i18n
$ npm install vue-i18n
```

@@ -34,6 +33,7 @@

## browserify
## duo
```shell
$ npm install vue-i18n
```javascript
var i18n = require('kazupon/vue-i18n')
```

@@ -44,5 +44,3 @@

## v-t directive
```js
```javascript
var Vue = require('vue')

@@ -68,3 +66,3 @@ var i18n = require('vue-i18n')

lang: 'ja',
locales: locales // NOTE: 'resources' is deprecated
locales: locales
})

@@ -82,3 +80,3 @@

<div id="test-i18n" class="message">
<p v-t="message.hello"></p>
<p>{{ $t("message.hello") }}</p>
</div>

@@ -95,74 +93,84 @@ ```

## Vue.t function
```js
var Vue = require('vue')
var i18n = require('vue-i18n')
# Formatting
// ready translated locales
## Named formatting
Locale the following:
```javascript
var locales = {
en: {
message: {
hello: 'the world'
hello: '{msg} world'
}
},
ja: {
message: {
hello: 'ザ・ワールド'
}
}
}
```
// set plugin
Vue.use(i18n, {
lang: 'en',
locales: locales
})
Template the following:
console.log(Vue.t('message.hello')) // output the 'the wolrd'
```html
<div class="message">
<p>{{ $t('message.hello', { msg: "hello"}) }}</p>
</div>
```
## $t method (for 0.11.4 later)
Output the following:
```html
<div id="message">
Message:<br>{{$t('message.hello')}}
<div class="message">
<p>hello world</p>
</div>
```
```js
var Vue = require('vue')
var i18n = require('vue-i18n')
## List formatting
// ready translated locales
Locale the following:
```javascript
var locales = {
en: {
message: {
hello: 'the world'
hello: '{0} world'
}
},
ja: {
message: {
hello: 'ザ・ワールド'
}
}
}
```
// set plugin
Vue.use(i18n, {
lang: 'en',
locales: locales
})
Template the following:
new Vue().$mount('#message')
```html
<div class="message">
<p>{{ $t('message.hello', ["hello"]) }}</p>
</div>
```
render the following:
Output the following:
```html
<div id="message">
Message:<br>the world
<div class="message">
<p>hello world</p>
</div>
```
# API
## #$t(keypath, [lang], [arguments])
- keypath: `String` **required**
- lang: `String` **optional**
- arguments: `Array | Object` **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`.
# Contributing
- Fork it !
- Create your top branch from `dev`: `git branch my-new-topic origin/dev`
- Commit your changes: `git commit -am 'Add some topic'`
- Push to the branch: `git push origin my-new-topic`
- Submit a pull request to `dev` branch of `vuejs/vue-validator` repository !
# Testing

@@ -175,6 +183,2 @@

# TODO
See the `TODO.md`
# License

@@ -184,2 +188,2 @@

See the `LICENSE`.
[MIT](http://opensource.org/licenses/MIT)

@@ -22,13 +22,3 @@ /**

.evaluate(function () {
return document.querySelector('#translation p.directive').innerText
}, function (text) {
expect(text).to.be.eql('hello')
})
.evaluate(function () {
return document.querySelector('#translation p.static').innerText
}, function (text) {
expect(text).to.be.eql('world')
})
.evaluate(function () {
return document.querySelector('#translation div.instance').innerHTML
return document.querySelector('#message').innerHTML
}, function (html) {

@@ -35,0 +25,0 @@ expect(html).to.be.eql('Hello kazupon !!<br>How are you?')

@@ -33,11 +33,13 @@ /**

before(function () {
Vue.use(i18n, {
lang: 'en',
locales: locales
})
})
describe('$t', function () {
describe('en language locale', function () {
it('should translate an english', function () {
Vue.use(i18n, {
lang: 'en',
locales: locales
})
var vm = new Vue()

@@ -50,9 +52,4 @@ expect(vm.$t('message.hello')).to.be.eql(locales.en.message.hello)

it('should translate a japanese', function () {
Vue.use(i18n, {
lang: 'ja',
resources: locales
})
var vm = new Vue()
expect(vm.$t('message.hello')).to.be.eql(locales.ja.message.hello)
expect(vm.$t('message.hello', 'ja')).to.be.eql(locales.ja.message.hello)
})

@@ -62,9 +59,2 @@ })

describe('key argument', function () {
before(function () {
Vue.use(i18n, {
lang: 'en',
locales: locales
})
})
describe('not specify', function () {

@@ -93,9 +83,2 @@ it('should return empty string', function () {

describe('format arguments', function () {
before(function () {
Vue.use(i18n, {
lang: 'en',
locales: locales
})
})
describe('named', function () {

@@ -120,7 +103,2 @@ it('should return replaced string', function () {

it('should return empty string', function () {
Vue.use(i18n, {
lang: 'en',
locales: locales
})
var vm = new Vue()

@@ -133,7 +111,2 @@ expect(vm.$t('message.hello', 'ja')).to.be.eql(locales.ja.message.hello)

it('should return replaced string', function () {
Vue.use(i18n, {
lang: 'en',
locales: locales
})
var vm = new Vue()

@@ -147,22 +120,27 @@ expect(vm.$t('message.format.list', 'ja', ['kazupon']))

describe('Vue.t', function () {
describe('en', function () {
it('should translate an english', function () {
Vue.use(i18n, {
lang: 'en',
locales: locales
})
expect(Vue.t('message.hello')).to.be.eql(locales.en.message.hello)
describe('reactive translation', function () {
it('should translate', function (done) {
var ViewModel = Vue.extend({
template: '<div><p>{{ $t("message.hello", lang) }}</p></div>',
data: function () {
return { lang: 'en' }
},
el: function () {
var el = document.createElement('div')
el.id = 'translate-reactive'
document.body.appendChild(el)
return el
}
})
})
describe('ja', function () {
it('should translate a japanese', function () {
Vue.use(i18n, {
lang: 'ja',
resources: locales
var vm = new ViewModel()
var el = document.querySelector('#translate-reactive')
Vue.nextTick(function () {
expect(el.textContent).to.be.eql(locales.en.message.hello)
vm.$set('lang', 'ja') // set japanese
Vue.nextTick(function () {
expect(el.textContent).to.be.eql(locales.ja.message.hello)
done()
})
expect(Vue.t('message.hello')).to.be.eql(locales.ja.message.hello)
})

@@ -173,151 +151,21 @@ })

describe('v-t', function () {
before(function () {
Vue.config.async = false
})
after(function () {
Vue.config.async = true
})
describe('basic', function () {
describe('en', function () {
it('should translate an english', function () {
Vue.use(i18n, {
lang: 'en',
locales: locales
})
var ViewModel = Vue.extend({
template: '<p v-t="message.hello"></p>',
el: function () {
var el = document.createElement('div')
el.id = 'translate-en'
document.body.appendChild(el)
return el
}
})
new ViewModel()
expect(document.querySelector('#translate-en p').textContent)
.to.be.eql(locales.en.message.hello)
})
})
describe('ja', function () {
it('should translate a japanese', function () {
Vue.use(i18n, {
lang: 'ja',
resources: locales
})
var ViewModel = Vue.extend({
template: '<p v-t="message.hello"></p>',
el: function () {
var el = document.createElement('div')
el.id = 'translate-ja'
document.body.appendChild(el)
return el
}
})
new ViewModel()
expect(document.querySelector('#translate-ja p').textContent)
.to.be.eql(locales.ja.message.hello)
})
})
})
describe('lang resource not found', function () {
it('should not translate', function () {
Vue.use(i18n, {
lang: 'it',
locales: locales
})
var ViewModel = Vue.extend({
template: '<p v-t="message.hello"></p>',
el: function () {
var el = document.createElement('div')
el.id = 'translate-it'
document.body.appendChild(el)
return el
describe('translate component', function () {
it('should translate', function (done) {
var ViewModel = Vue.extend({
template: '<div><p>{{ $t("message.hello") }}</p><hoge></hoge></div>',
el: function () {
var el = document.createElement('div')
el.id = 'translate-parent'
document.body.appendChild(el)
return el
},
components: {
hoge: {
template: '<p id="translate-child">{{* $t("message.hoge") }}</p>'
}
})
new ViewModel()
expect(document.querySelector('#translate-it p').textContent)
.to.be.eql('message.hello')
}
})
})
new ViewModel()
describe('resource key not found', function () {
it('should not translate', function () {
Vue.use(i18n, {
lang: 'en',
locales: locales
})
var ViewModel = Vue.extend({
template: '<p v-t="message.foo"></p>',
el: function () {
var el = document.createElement('div')
el.id = 'translate-en-key-nothing'
document.body.appendChild(el)
return el
}
})
new ViewModel()
expect(document.querySelector('#translate-en-key-nothing p').textContent)
.to.be.eql('message.foo')
})
})
describe('resource key empty', function () {
it('should not translate', function () {
Vue.use(i18n, {
lang: 'en',
locales: locales
})
var ViewModel = Vue.extend({
template: '<p v-t=""></p>',
el: function () {
var el = document.createElement('div')
el.id = 'translate-key-empty'
document.body.appendChild(el)
return el
}
})
new ViewModel()
expect(document.querySelector('#translate-key-empty p').
textContent).to.be.eql('')
})
})
describe('translate component module', function () {
it('should translate', function () {
Vue.use(i18n, {
lang: 'en',
locales: locales
})
var ViewModel = Vue.extend({
template: '<div><p v-t="message.hello"></p><div v-component="hoge"></div></div>',
el: function () {
var el = document.createElement('div')
el.id = 'translate-parent'
document.body.appendChild(el)
return el
},
components: {
hoge: Vue.extend({
template: '<p id="translate-child" v-t="message.hoge"></p>'
})
}
})
new ViewModel()
Vue.nextTick(function () {
var child_el = document.querySelector('#translate-child')

@@ -328,2 +176,4 @@ expect(child_el.textContent).to.be.eql(locales.en.message.hoge)

expect(parent_el.textContent).to.be.eql(locales.en.message.hello)
done()
})

@@ -330,0 +180,0 @@ })

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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