vue-i18n
vue-i18n copied to clipboard
Default $tc plurialization in different language
Clear and concise description of the problem
Consider this translation:
"en": {
"total": "0 results | {n} result | {n} results",
}
Here is the output:
$tc('total', 0) => 0 results
$tc('total', 1) => 1 result
$tc('total', 2) => 2 results
If the count in $tc is undefined
$tc('total', someVariable) => 1 result
Suggested solution
Undefined should be the same as 0.
Alternative
I could put a fallback value for every $tc, but this can be hard for nested object as Vue 2 doesn't accept optional chaining in template.
{{ $tc('total', items.meta.total || 0) }}
Additional context
No response
Validations
- [X] Read the Contributing Guidelines
- [X] Read the Documentation
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
There seem to be a pluralizationRules function which i could duplicate and override, but it seem like there should be a way to set the default index without overrider the function because I'm not trying to implement custom pluralization behavior.
Also the doc is not clear on how to override this function.
var defaultImpl = function (_choice, _choicesLength) {
_choice = Math.abs(_choice);
if (_choicesLength === 2) {
return _choice
? _choice > 1
? 1
: 0
: 1
}
return _choice ? Math.min(_choice, 2) : 0
};
From the docs:
The value of plural is handled with default 1.
But it doesn't make sense. Following this exemple from the docs.
en: {
apple: 'no apples | one apple | {count} apples'
}
$tc("apple", undefined) => one apple
but it would make much more sense with no apples as the default
The issue isn't just that it choose the second string, but also that it pass a value of 1 to {n} so following this exemple:
en: {
apple: '{n} apples | {n} apple | {n} apples'
}
$tc("apple", undefined) => 1 apple