You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚠️ This may be a big architectural change. However, I think it's worth doing for future extendability.
In need of propose a new feature (#214), I spent some time reading the source code. And found that list formatting is implemented individually with named formatting. For messages interpolated with "numbers":
messages: {en: {msg: 'This is {0} and {1}.'}}
I could only pass an array:
<div>{{ $t('msg', ['bold', 'italic']) }}</div>
Passing an object (that look like an array) is not allowed:
Following warning message appears, and the translation fails:
[vue-i18n] Type of token 'list' and format of value 'named' don't match!
This is a bit too strict to the users. And it doesn't behave consistently with JavaScript.
// These two expressions output the same result: ['0', '1']Object.keys(['bold','italic'])Object.keys({'0': 'bold','1': 'italic'})
Most i18n libs or components like Dojo, Angular, etc are making list formatting syntax sugar of named formatting. Since in JavaScript, arrays are objects too.
This benefits both sides:
To the users, it brings flexibility of formatting messages interpolated with "numbers".
To the developers, reuse of such mechanism makes it cleaning under the hood. And easier to ship new features.
The text was updated successfully, but these errors were encountered:
In need of propose a new feature (#214), I spent some time reading the source code. And found that list formatting is implemented individually with named formatting. For messages interpolated with "numbers":
I could only pass an array:
Passing an object (that look like an array) is not allowed:
Following warning message appears, and the translation fails:
This is a bit too strict to the users. And it doesn't behave consistently with JavaScript.
Most i18n libs or components like Dojo, Angular, etc are making list formatting syntax sugar of named formatting. Since in JavaScript, arrays are objects too.
This benefits both sides:
The text was updated successfully, but these errors were encountered: