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 :).

2 Answers 2

8

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

1
  • You're welcome. Glad I could help Commented Dec 11, 2014 at 8:54
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.