In zf2
you have the view helper translatePlural
. Which can be use as followed;
echo $this->translatePlural('car', 'cars', $num);
So when $num == 1
it says car
else cars
(depending on the plural rule but for now use the english rule).
To translate this, by file. You have to use an array like;
'car' => [
'auto',
'autos',
],
So now you get auto
if $num == 1
else autos
.
If you have some where else in your code to translate car
you could do translate('car')
but that will return to a notice array to string coverstion
, which is obvious not what we want.
So to be able to also translate just car
and use the plural I now have to modify the code to something like;
echo $this->translatePlural('car_plural', 'cars', $num);
And the language config;
'car_plural' => [
'auto',
'autos',
],
'car' => 'auto',
And you need to have to add an english translation for car_plural
. So the translatePlural
default messages become prety much useless in a default setup, unless you use translatePlural
not for translation but for just to choose between car
or cars
and not translating it.
But if instead the translatePlural
just looked at $num
then use the pluralRule
to choose between singular (car) or plural (cars). Then use the translate
helper to translate the singular or plural, you can have an easy config like and the default message all of sudden work again;
'car' => 'auto',
'cars' => 'autos',
No weird keys, you don't need english translation's or something else weird.
So the question /tldr;
Why does ZF2 plural uses an array and not just check which one to use and translate that one? Seems to me a way better method.