1

I am needing translate parts of a text (in twig).

Something like that:

// page.html.twig

    ...
    {{ text | trans ({}, 'MyprojectMyBundle')}} 

Supos variable 'text' have the string: "Value is between 5 and 10"

In translation arquive I have:

// Project/MyBundle/Resources/Translations/MyprojectMyBundle.pt_BR.yml

...
Value is between and : "Valor está entre e"

How can I escape the numbers (5 and 10) in translation? I need:

Value is between 5 and 10 -> Valor está entre 5 e 10

Value is between 50 and 60 -> Valor está entre 50 e 60

etc...

Munir
  • 739
  • 2
  • 14
  • 38

1 Answers1

0

You can use placeholders, so in your translation file you would have:

// Project/MyBundle/Resources/Translations/MyprojectMyBundle.pt_BR.yml

...
Value is between %min% and %max%: "Valor está entre %min% e %max%"

and then in your template you can use the following:

{{ text | trans({'%min%': '5', '%max%': '10'}, "MyprojectMyBundle") }}

where text = 'Value is between %min% and %max%'

user1207727
  • 1,543
  • 1
  • 15
  • 18
  • but min and max will change every time – Munir Mar 14 '12 at 20:07
  • Yes, you can replace the '5' & '10' with template variables which contain the values, eg {{ text | trans({'%min%': minval, '%max%': maxval}, "MyprojectMyBundle") }} – user1207727 Mar 14 '12 at 20:10
  • Works! But 'text' now is a array with ('text', 'min', 'max). So I can call {{ text.text | trans({'%min%': 'text.min', '%max%': 'text.max'}, "MyprojectMyBundle") }} Thx! – Munir Mar 14 '12 at 20:44
  • awesomeness! glad to be of assistance – user1207727 Mar 14 '12 at 20:46