From bed9c39b8026fa7c8a94601e90df2d3cf3b86fe1 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 14 Jan 2019 09:09:53 +0900 Subject: [PATCH] :bug: bug(index): fix flat path based key issue closes #349 --- src/index.js | 5 ++++- test/unit/fixture/index.js | 6 ++++-- test/unit/issues.test.js | 7 +++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index bfbee4e26..570a92447 100644 --- a/src/index.js +++ b/src/index.js @@ -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({ diff --git a/test/unit/fixture/index.js b/test/unit/fixture/index.js index 6e12dc185..949863ee8 100644 --- a/test/unit/fixture/index.js +++ b/test/unit/fixture/index.js @@ -61,7 +61,8 @@ export default { ], issues: { arrayBugs: ['bug1', 'bug2'] - } + }, + 'foo.bar.buz': 'hello flat key!' }, ja: { message: { @@ -101,6 +102,7 @@ export default { ], issues: { arrayBugs: ['バグ1', 'バグ2'] - } + }, + 'foo.bar.buz': 'こんにちは、フラットなキーさん!' } } diff --git a/test/unit/issues.test.js b/test/unit/issues.test.js index 5fd2e9a0c..55effc762 100644 --- a/test/unit/issues.test.js +++ b/test/unit/issues.test.js @@ -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')