Open Soviut opened 4 years ago
I think $tc should focus for pluralization purpose. Overloading for boolean complicates $tc in terms of both usage and implementation.
Switching translation by boolean seems to have many use case (e.g. valid/invalid, enabled/disabled, full/vacant). So I think adding new method for boolean , like $tb or something, might be handy.
Is this feature still wanted? I would like to try to submit a PR for this feature issue. It looks useful. This feature would only works with true or false, right? What should be the behavior when null or undefined is passed? Should we support a fallback message (third value option) for that case?
@robinsondotnet I'd definitely still like this feature and can help you with the review if you want.
The basic concept is that it would work for things like (on
, off
), (yes
, no
), (valid
, invalid
), (visible
, hidden
), etc.
Regarding null
, I'd say that null
, false
, undefined
and any other falsey values should yield the "false" value.
Similarly, I would consider the false condition to be the fallback.
my workaround for this situation is
{
"validity": "invalid | valid" // false text first
}
t('validity', +isValid + 1)
the unary + operator turns false to 0 and true to 1. by adding one the result is either 1 or 2
Pluralization allows simple shortcut syntax like
Which can be called with
Which produces
I would like a similar shorthand for booleans where the first item is
true
and the second item isfalse