Symfony2 Zoom Tag

I added a translation service for my Symfony2 project. I use it in both controllers and twig templates. It’s fine tuned and all the {% trans %} tags work the way they want. But in some cases I need to use the tag {% transchoice %} , and it does not receive the translation. Here is an example from my code.

 {% transchoice post['comments']['count'] %} {0} Comments| {1} Comment| ]1,Inf] Comments {% endtranschoice %} 

They also tried to write it on one line.

I get the right choice for counting comments, but the word itself is not translated. As a translator, he cannot find the appropriate translation. In messages.de.yml I have

 Comment: "Kommentar" Comments: "Kommentare" 

Is this something wrong with my transcription syntax? Maybe I need to place spaces somewhere or something like that?

+6
source share
1 answer

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 do I use it:

 <h2>{{ 'search.results.summary' | transchoice(search_count, { '%search_text%': search_text, '%search_count%': search_count}) }}</h2> 

As you can see, I do not use complex notation as a source for my translation, since it is rather useless and will make the template less readable. Instead, I put a line separated by a dot representing the semantic value of my line.

In your case, I think the right 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.

+11
source

Source: https://habr.com/ru/post/909549/


All Articles