I have added the translator service for my Symfony2 project. I use it both in controllers and in twig templates. It's configured fine and all the {% trans %}
tags work as they mean to. But in some cases I need to use the {% transchoice %}
tag, and it's not getting the translation. Here is an example from my code.
{% transchoice post['comments']['count'] %}
{0} Comments| {1} Comment| ]1,Inf] Comments
{% endtranschoice %}
Also have tried writing this in one line.
I get the correct choice for the comment count, but the word itself is not beeng translated. Like the translator is not able to find the corresponding translation. In the messages.de.yml I have
Comment: "Kommentar"
Comments: "Kommentare"
Is it something wrong with my transchoice syntax? Maybe I need to place spaces somewhere, or anything like that?
In your translation file, you should write this:
{0} Comments| {1} Comment| ]1,Inf] Comments: "{0} Kommentare| {1} Kommentar| ]1,Inf] Kommentare"
UPDATE: An xliff example that works for me :
<trans-unit id="search.results.summary">
<source>search.results.summary</source>
<target>{0}Pas d'annotations trouvée pour "%search_text%"|{1}Une annotation trouvée pour "%search_text%"|]1,Inf]%search_count% annotations trouvées pour "%search_text%"</target>
</trans-unit>
How I use it:
<h2>{{ 'search.results.summary' | transchoice(search_count, {
'%search_text%': search_text,
'%search_count%': search_count}) }}</h2>
As you see, I don't use the complicated notation as the source for my translation, since it is pretty useless and would make the template less readable. Instead, I put a dot-separated string representing the semantical value of my string.
In your case, I guess the correct thing to use would be something like this:
comment.summary: "{0} Kommentare|{1} Kommentar|]1,Inf] Kommentare"
and
{% transchoice post['comments']['count'] %}
'comment.summary'
{% endtranschoice %}
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With