Skip to content

Commit

Permalink
🐛 bug(sfc): fix cannot parse custom block locale messages
Browse files Browse the repository at this point in the history
Close #173
  • Loading branch information
kazupon committed Jun 10, 2017
1 parent 60ba19d commit 32eb3a7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,15 @@ export default class VueI18n {
}

getLocaleMessage (locale: Locale): LocaleMessageObject {
return looseClone(this._vm.messages[locale])
return looseClone(this._vm.messages[locale] || {})
}

setLocaleMessage (locale: Locale, message: LocaleMessageObject): void {
this._vm.messages[locale] = message
}

mergeLocaleMessage (locale: Locale, message: LocaleMessageObject): void {
this._vm.messages[locale] = Vue.util.extend(this.getLocaleMessage(locale), message)
this._vm.messages[locale] = Vue.util.extend(this._vm.messages[locale] || {}, message)
}

getDateTimeFormat (locale: Locale): DateTimeFormat {
Expand Down
4 changes: 2 additions & 2 deletions src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default {
})
} catch (e) {
if (process.env.NODE_ENV !== 'production') {
warn(`Cannot parse locale messages via custom blocks.`)
warn(`Cannot parse locale messages via custom blocks.`, e)
}
}
}
Expand All @@ -38,7 +38,7 @@ export default {
options.i18n.messages = JSON.parse(options.__i18n)
} catch (e) {
if (process.env.NODE_ENV !== 'production') {
warn(`Cannot parse locale messages via custom blocks.`)
warn(`Cannot parse locale messages via custom blocks.`, e)
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions test/unit/issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,23 @@ describe('issues', () => {
}).then(done)
})
})

describe('#173', () => {
it('should be translated', done => {
const Component = Vue.extend({
__i18n: JSON.stringify({
en: { custom: 'custom block!' }
}),
render (h) {
return h('p', { ref: 'custom' }, [this.$t('custom')])
}
})
const vm = new Component({
i18n: new VueI18n({ locale: 'en' })
}).$mount()
nextTick(() => {
assert.equal(vm.$refs.custom.textContent, 'custom block!')
}).then(done)
})
})
})

0 comments on commit 32eb3a7

Please sign in to comment.