Skip to content

Commit

Permalink
fix v-t pluralisation when choice is 0 (#882)
Browse files Browse the repository at this point in the history
* fix v-t pluralisation when choice is 0

* test case for v-t with a choice of 0

Co-authored-by: Mike Jacoutot <mike.jacoutot@jazznetworks.com>
  • Loading branch information
mikejacoutot and Mike Jacoutot committed May 19, 2020
1 parent 179f0b1 commit 70f142d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function t (el: any, binding: Object, vnode: any): void {
}

const vm: any = vnode.context
if (choice) {
if (choice != null) {
el._vt = el.textContent = vm.$i18n.tc(path, choice, ...makeParams(locale, args))
} else {
el._vt = el.textContent = vm.$i18n.t(path, ...makeParams(locale, args))
Expand Down
20 changes: 20 additions & 0 deletions test/unit/directive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,26 @@ describe('custom directive', () => {
assert.strictEqual(vm.$refs.text._vt, 'cars')
}).then(done)
})

it('should allow a zero choice', done => {
const vm = createVM({
i18n,
render (h) {
// <p ref="text" v-t="{path: 'plurals.apple', choice: 0}"></p>
return h('p', { ref: 'text', directives: [{
name: 't', rawName: 'v-t', value: ({ path: 'plurals.apple', choice: 0 }), expression: { path: 'plurals.apple', choice: 0 }
}] })
}
})
nextTick(() => {
assert.strictEqual(vm.$refs.text.textContent, 'no apples')
assert.strictEqual(vm.$refs.text._vt, 'no apples')
vm.$forceUpdate()
}).then(() => {
assert.strictEqual(vm.$refs.text.textContent, 'no apples')
assert.strictEqual(vm.$refs.text._vt, 'no apples')
}).then(done)
})
})

describe('preserve content', () => {
Expand Down

0 comments on commit 70f142d

Please sign in to comment.