6

I have a problem using translate function.

This works:

$this->__("You can contact %s by calling %s.", $name, $phone);

But this doesn't:

$this->__("You can contact %1$s by calling %2$s.", $name, $phone);

And the problem is, that I would like to translate this as: "Please call %2$s to speak to %1$s." so the order is important.

Do you have any ideas why the second example doesn't work? I would appreciate any suggestions :).

Alan
  • 927
  • 1
  • 18
  • 33

2 Answers2

8

Magento uses PHPs vsprintf method. So instead of %1$s you'll have to use %1\$s

Sander Mangel
  • 37,528
  • 5
  • 80
  • 148
0

I'm propose other method for display multiple variables with magento2.

I use this:

echo __('My name is [%1] and lastname(%2)',$name,$lastname);

Regards

Marc
  • 212
  • 2
  • 8