Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge locale messages should preserve non-conflicting keys #458

Closed
viniciuszani opened this issue Nov 6, 2018 · 0 comments
Closed

Merge locale messages should preserve non-conflicting keys #458

viniciuszani opened this issue Nov 6, 2018 · 0 comments
Labels
Type: Bug Bug or Bug fixes

Comments

@viniciuszani
Copy link

Problem

When using i18n.mergeLocaleMessage, it is expected that keys that do not overlap entirely are preserved.
Fiddle to simulate the problem: https://jsfiddle.net/v6ec0mdx/

Given two objects with the same keys, if they have different child properties, the resulting object should be merged.

const module1 = {
  shared: {
  // key1 will be overwritten by mergeLocaleMessage
     key1: 'I am part of a shared module, but spread accross translation files!'
  }
}

const module2 = {
  shared: {
     key2: 'I am an extension of a shared module!'
  }
}

i18n.mergeLocaleMessage('en', module1)
// later in another file...
i18n.mergeLocaleMessage('en', module2)
// shared.key1 is lost

Suggestion

In i18n's src/index.js, instead of using Vue's extend method (check here), which does not preserve conflicting keys (or even deep checks conflicts), use i18n's utility merge method

The affected line is here:

this._vm.$set(this._vm.messages, locale, Vue.util.extend(this._vm.messages[locale] || {}, message))

@viniciuszani viniciuszani changed the title Merge locale messages should preserve 'deep' keys Merge locale messages should preserve non-conflicting keys Nov 6, 2018
@kazupon kazupon added the Type: Bug Bug or Bug fixes label Nov 8, 2018
@kazupon kazupon closed this as completed in 1798490 Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug or Bug fixes
Projects
None yet
Development

No branches or pull requests

2 participants