2

I'm asking if it's possible to use translations in Symfony2 as, for example, sprint_f() PHP functions does. By using sprint_f() is so easy as:

$message = 'Are you sure to delete the %element%?';
echo sprintf($message , "element_name");

And the output will be: "Are you sure to delete the element_name?", that's easy. Now I have the translation file in YML format and I wrote this:

delete.message: Are you sure to delete the %element%?

But this will work? I check docs here and here but since I'm using BazingaJSTranslationBundle I don't know how to get this working on this scenario. Any help or advice?

ReynierPM
  • 17,594
  • 53
  • 193
  • 363
  • Did you try the example given in the `Readme` of the bundle. Right on the link you provided. [The docs say](https://github.com/willdurand/BazingaJsTranslationBundle/blob/master/Resources/doc/index.md#message-placeholders--parameters): `will replace each "%foo%" in the message by "bar".` – ferdynator Apr 07 '14 at 16:12
  • @ferdynator yes, you're right but this is not my concern since I ask for how to did this in the `messages.en.yml` file – ReynierPM Apr 07 '14 at 16:20

1 Answers1

2

Add this to your messages.en.yml:

delete.message: Are you sure to delete the %element%?

Now call it in js:

Translator.trans('delete.message', { "element" : "YOUR VALUE" }, 'messages');

Explanation found in the BazingaJsTranslationBundle docs.

ferdynator
  • 6,245
  • 3
  • 27
  • 56