symfony2 translation with transchoice

svassr picture svassr · Jun 5, 2012 · Viewed 10.3k times · Source

I'm translating the following key in activity.fr.yml

user.list.link: '{1}et %count% autre|]1,Inf[voir les %count% autres'

using tranchoice

<a href="{{ moreLink }}" >{% transchoice count from "activity" %}user.list.link{% endtranschoice %}</a>

and I get the following error

An exception has been thrown during the rendering of a template ("Unable to choose a translation.")

I think the translation has been found otherwise I wouldn't get an error about Unable to choose a translation but the key itself.

Also all the other keys from the same yaml even other tranchoice are well translated.

I followed the doc and tried adding with {'%count%': count} with no success.

Does someone have an idea about what's wrong here ? Thanks in advance

Answer

svassr picture svassr · Jun 13, 2012

The syntax was fine but the value pass as %count% couldn't be negative neither equal to 0 because there was no {0} defintion in the pluralised string. So I had a test to make sure the value was >= 0 and modified the string like this and it fixes it.

user.list.link: '{0}|{1}et %count% autre|]1,Inf[voir les %count% autres'