Reputation: 5668
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
Upvotes: 2
Views: 10487
Reputation: 5668
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'
Upvotes: 6
Reputation: 1204
You need to pass the parameter used to determine the translation which will be choose.
Look at the following example found in the doc:
{% transchoice count with {'%name%': 'Fabien'} from "app" %}
{0} There is no apples|{1} There is one apple|]1,Inf] There are %count% apples
{% endtranschoice %}
Adapted to your example:
{% transchoice count with {'%count%': count} from "activity" %}
user.list.link
{% endtranschoice %}
If it doesn't work, maybe your translation is not found. So, symfony use your key as fallback and cannot determine a valid choice because your key doesn't support this.
To check this, try to use a key like this:
user.list.link | user.list.link.many
Don't forget to use the same key in your activity catalog.
Upvotes: 2