2

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

svassr
  • 5,538
  • 5
  • 44
  • 63

2 Answers2

6

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'
svassr
  • 5,538
  • 5
  • 44
  • 63
2

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.

Olivier Dolbeau
  • 1,204
  • 9
  • 11
  • I think the translation has been found otherwise I wouldn't get an error about `Unable to choose a translation` but the key itself. – svassr Jun 05 '12 at 13:07
  • by adding your suggestion `{% transchoice count with {'%count%':count} from "activity" %}user.list.link.link|user.list.many{% endtranschoice %}` I get `user.list.link.many` in place of the string in teh template – svassr Jun 05 '12 at 13:07
  • If the translation isn't found, it's the key which is used. And it's not possible to choose a translation with such a key. Maybe the error is due to the spaces between your translation and in my example. Try `user.list.link|user.list.link.many`. (And of course, use the same in your catalog and clear your cache.) – Olivier Dolbeau Jun 05 '12 at 17:41