Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Merge locale messages should preserve non-conflicting keys #458

Description

@viniciuszani

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions