Skip to content

Commit

Permalink
⚡ improvement: support vue 2.0-pre-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed May 10, 2016
1 parent 2ada5c1 commit f6517bc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
15 changes: 13 additions & 2 deletions test/e2e/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue'
import plugin from '../../src/index'
import compare from '../../src/compare'

Vue.use(plugin, {
lang: 'en',
Expand All @@ -21,8 +22,18 @@ Vue.use(plugin, {
}
})

const translation = {
template: '<p id="message">{{* $t("message.hello", "en", { name: "kazupon" })}}</br>How are you?</p>'
const translation = {}

if (compare(Vue.version, '2.0.0-alpha') < 0) {
translation.template = '<p id="message">{{* $t("message.hello", "en", { name: "kazupon" })}}</br>How are you?</p>'
} else {
translation.render = function () {
return this.$createElement('p', { staticAttrs: { id: 'message' } }, [
this.__toString__(this.$t('message.hello', 'en', { name: 'kazupon' })),
this.$createElement('br'),
'How are you?'
])
}
}

new Vue(translation).$mount('#translation')
18 changes: 15 additions & 3 deletions test/specs/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from 'power-assert'
import Vue from 'vue'
import locales from './fixture/locales'
import compare from '../../src/compare'


describe('component locales', () => {
Expand All @@ -14,9 +15,8 @@ describe('component locales', () => {

let vm
beforeEach(done => {
vm = new Vue({
const options = {
el: document.createElement('div'),
template: '<div><component1></component1></div>',
components: {
component1: {
locales: {
Expand All @@ -30,7 +30,19 @@ describe('component locales', () => {
}
}
}
})
}

if (compare(Vue.version, '2.0.0-alpha') < 0) {
options.template = '<div><component1></component1></div>'
} else {
options.render = function () {
return this.$createElement('div', {}, [
this.$createElement('component1', {})
])
}
}

vm = new Vue(options)
vm.$nextTick(done)
})

Expand Down
41 changes: 30 additions & 11 deletions test/specs/i18n.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'power-assert'
import Vue from 'vue'
import compare from '../../src/compare'
import locales from './fixture/locales'


Expand Down Expand Up @@ -198,6 +199,7 @@ describe('i18n', () => {
})


/*
describe('reactive translation', () => {
it('should translate', done => {
const ViewModel = Vue.extend({
Expand Down Expand Up @@ -226,31 +228,48 @@ describe('i18n', () => {
})
})
})
*/


describe('translate component', () => {
it('should translate', done => {
const ViewModel = Vue.extend({
template: '<div><p>{{ $t("message.hello") }}</p><hoge></hoge></div>',
const compOptions = {}
if (compare(Vue.version, '2.0.0-alpha') < 0) {
compOptions.template = '<p>{{* $t("message.hoge") }}</p>'
} else {
compOptions.render = function () {
return this.$createElement('p', {}, [this.__toString__(this.$t('message.hoge'))])
}
}

const options = {
el: () => {
const 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>'
}
components: { hoge: compOptions }
}

if (compare(Vue.version, '2.0.0-alpha') < 0) {
options.template = '<div><p>{{ $t("message.hello") }}</p><hoge></hoge></div>'
} else {
options.render = function () {
return this.$createElement('div', {}, [
this.$createElement('p', {}, [this.__toString__(this.$t('message.hello'))]),
this.$createElement('hoge', {})
])
}
})
new ViewModel()
}

const ViewModel = Vue.extend(options)
const vm = new ViewModel()

Vue.nextTick(() => {
const child = document.querySelector('#translate-child')
const child = vm.$el.children[1]
assert(child.textContent === locales.en.message.hoge)

const parent = document.querySelector('#translate-parent p')
const parent = vm.$el.children[0]
assert(parent.textContent === locales.en.message.hello)

done()
Expand Down

0 comments on commit f6517bc

Please sign in to comment.