Skip to content

Commit

Permalink
🐛 bug(index): fix flat path based key issue
Browse files Browse the repository at this point in the history
closes #349
  • Loading branch information
kazupon committed Jan 14, 2019
1 parent 7da65d0 commit bed9c39
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ export default class VueI18n {

this._exist = (message: Object, key: Path): boolean => {
if (!message || !key) { return false }
return !isNull(this._path.getPathValue(message, key))
if (this._path.getPathValue(message, key)) { return true }
// fallback for flat key
if (message[key]) { return true }
return false
}

this._initVM({
Expand Down
6 changes: 4 additions & 2 deletions test/unit/fixture/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export default {
],
issues: {
arrayBugs: ['bug1', 'bug2']
}
},
'foo.bar.buz': 'hello flat key!'
},
ja: {
message: {
Expand Down Expand Up @@ -101,6 +102,7 @@ export default {
],
issues: {
arrayBugs: ['バグ1', 'バグ2']
}
},
'foo.bar.buz': 'こんにちは、フラットなキーさん!'
}
}
7 changes: 7 additions & 0 deletions test/unit/issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ describe('issues', () => {
})
})

describe('#349', () => {
it('should be existed', done => {
assert(vm.$te('foo.bar.buz') === true)
done()
})
})

describe('#377', () => {
it('should be destroyed', done => {
const el = document.createElement('div')
Expand Down

0 comments on commit bed9c39

Please sign in to comment.