intlify / vue-i18n-loader

:globe_with_meridians: vue-i18n loader for custom blocks
MIT License
267 stars 29 forks source link

Inconsistencies between i18n tag and messages object #30

Closed mzdr closed 4 years ago

mzdr commented 5 years ago

Hey @kazupon,

I think I stumbled upon something. I have this strange unexpected behaviour where the index of an array item is not always of type number. I created a reproduction repository for you to check out:

  1. git clone git@github.com:mzdr/vue-i18n-loader-array-index-issue.git
  2. cd vue-i18n-loader-array-index-issue
  3. npm install
  4. npm run serve

As you see I have defined 2 arrays. One in App.vue and one in main.js. The way they are defined is identical, just the values differ. But if I loop over the arrays in App.vue the index keys of the i18n array are of type string, where the index keys from the messages array of the configuration object are of type number.

I am expecting that both array keys will be of the same type if defined identically, no matter if they are defined in the i18n block or within the actual i18n configuration.

This looks like a bug to me, can you please elaborate? Thanks!

tex0l commented 5 years ago

I have a somewhat related issue: I have some entries of type Array in my i18n file. When injecting it in the Vue instance, I get a proper Array, but when writing it in an i18n block in my .vue file using vue-i18n-loader, I receive an Object, and I took the habit of doing an Array.from($t('key.to.array')) to ensure it works.

kazupon commented 4 years ago

This is a problem with the type definition of vue-i18n, close.

darkylmnx commented 4 years ago

This is a problem with the type definition of vue-i18n, close. @kazupon what kind of answer is that?

  1. Saying it's because of the type definition doesn't give a solution to this lack of consistency
  2. This inconsistency brings a lot of bugs in apps because "sometime it's an array" and "sometimes it's an object", why did you chose an object type definition when we explicitly give an array of translations?