1
{# this dont work  #}
{% trans %}Hello%name%!{% endtrans %}
{# this dont work  #}
{% trans with {'%name%':name} %}Hello%name%!{% endtrans %}

Did a bit of searching and found that translatioon has problems with spaces
I have removed spaces after Hello
Symfony2+Twig, variable in translation return "A message must be a simple text"
Symfony2 twig translate variable values in {% trans %} tag
How to translate with pluralization in Twig?

this works

{{ 'Hello' | trans }} {{ name }}

<?xml version="1.0"?>
 <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
  <file source-language="en" datatype="plaintext" original="file.ext">
   <body>
     <trans-unit id="191">
     <source>Hello</source>
     <target>Ciao</target>
     </trans-unit>
   </body>
 </file>
</xliff>

so have to use Filters?

am using Symfony v2.4 + twig v1.15
Could someone Clarify?

TIA

Community
  • 1
  • 1
Ritin
  • 401
  • 6
  • 15
  • 2
    Why do you remove the spaces? And please show us your messages file – Wouter J Dec 29 '13 at 08:15
  • @WouterJ All the above code is in a single html.twig so it works partially.. i havent included $twig->addExtension(new Twig_Extensions_Extension_I18n()); dont know where to add that. envrionment.php maybe and change the inclusion to this $this->addExtension(new Twig_Extensions_Extension_I18n()) ? – Ritin Jan 02 '14 at 07:47

1 Answers1

0

It can't be translated when you dont have a translation with <source>Hello%name%</source>

change it to this:

 {{ 'Hello'|trans({'%name%':'some name'}) }}

 <trans-unit id="191">
 <source>Hello</source>
 <target>Ciao %name%!</target>
 </trans-unit>

this should output "Ciao some name!"

DasBaconfist
  • 606
  • 6
  • 14