Closed mzdr closed 4 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.
This is a problem with the type definition of vue-i18n, close.
This is a problem with the type definition of vue-i18n, close. @kazupon what kind of answer is that?
- Saying it's because of the type definition doesn't give a solution to this lack of consistency
- 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?
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:
git clone git@github.com:mzdr/vue-i18n-loader-array-index-issue.git
cd vue-i18n-loader-array-index-issue
npm install
npm run serve
As you see I have defined 2 arrays. One in
App.vue
and one inmain.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!