Skip to content

Commit

Permalink
fix: key-value style messages broken after merging (#1717) (#1718)
Browse files Browse the repository at this point in the history
* fix: key-value style messages broken after merging (#1717)

* test: missing test for pull request #1718 (issue #1717)
  • Loading branch information
chojnicki authored Jan 31, 2024
1 parent ac619a9 commit ee5ef6e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/vue-i18n-core/src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2435,9 +2435,11 @@ export function createComposer(options: any = {}, VueI18nLegacy?: any): any {
__legacy && __legacy.mergeLocaleMessage(locale, message)
}
const _message = { [locale]: message }
for (const key in _message) {
if (hasOwn(_message, key)) {
handleFlatJson(_message[key])
if (flatJson) {
for (const key in _message) {
if (hasOwn(_message, key)) {
handleFlatJson(_message[key])
}
}
}
message = _message[locale]
Expand Down
16 changes: 16 additions & 0 deletions packages/vue-i18n-core/test/issues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1273,3 +1273,19 @@ test('issue #1615', async () => {
`false (...but this should be false)`
)
})

test('issue #1717', async () => {
const en = {
'a.b.c': 'Hello, Vue I18n'
}
const i18n = createI18n({
locale: 'en',
messages: {
en: {}
}
})
i18n.global.mergeLocaleMessage('en', en)
expect(i18n.global.getLocaleMessage('en')).toEqual({
'a.b.c': 'Hello, Vue I18n' // should not be transformed to nested object like in issue
})
})

0 comments on commit ee5ef6e

Please sign in to comment.