intlify / vue-i18n

Vue I18n for Vue 3
https://vue-i18n.intlify.dev/
MIT License
2.11k stars 324 forks source link

Add option to support working with flattened json using dot ('.') as separator #271

Open RobinB-Gbanga opened 3 years ago

RobinB-Gbanga commented 3 years ago

Currently, if I look up this key: $t('mainMenu.buttonStart')

The key is only found if I use a nested json:

{
  "mainMenu": {
    "buttonStart": "Start!"
  }
}

But not if I use a flat json representation:

{
  "mainMenu.buttonStart": "Start!"
}

For a current project, we are interfacing with a translation source that can only output flat json files. At the same time, however, we'd like to have the benefits of a namespaced/scoped key naming convention. For example, the tool we use in VSCode offers a nice tree view when using dots as namespace/scope separators.

It would be great if vue-i18n would offer a setting to support flattened json files (or, in other words, to treat the dot ('.') as a normal/literal character).

Thanks!

kazupon commented 3 years ago

Thank you for your feedback.

In order for vue-i18n-next to support this, it needs to support the custom message resolver I/F.

Since the message resolver is modularized, we need to extend the custom message resolver so that it can be optioned by vue-i18n. https://github.com/intlify/vue-i18n-next/tree/master/packages/message-resolver

kazupon commented 3 years ago

Fixed with #294

kazupon commented 3 years ago

Re-open, so #294 is breaking change. https://github.com/intlify/vue-i18n-next/issues/271