I am writing custom module in order to verify customers mobile number before checkout if the cart have products from specified type.

The message body sent to mobile operator passed to translation function

$messageContent = __('Use that code to verify').': '.$verifyCode;

The string have been translated in csv file but when I use like this to send http request to SMS gateway server it goes to the mobile like below:


How can I get the string for every store view in code


After @Max Stsepantsevich answer I turned off the inline translation and now I get only the English string.

I have that line in my custom module to translate

"Use that code to verify ","أستخدم هذا الكود للتفعيل ",module,Magento_Bundle

I added the following piece of code to emulate the store view but still get the english only see below:

$resolver = $this->om->get('\Magento\Framework\Locale\Resolver');

$resolver->emulate('2');//store view id
$content = urlencode(__('Use that code to verify '). $verifyCode);


Thanks in advance

  • Did you change locale in configuration for emulated store view?
    – Max
    Commented Jan 14, 2017 at 4:58
  • I don't know what are you talking about, Could you please let me know what I have to do? Commented Jan 15, 2017 at 7:00
  • I have the same issue, did you find a fix ? Thanks !
    – magentodev
    Commented Jun 3, 2019 at 14:35

2 Answers 2


Looks like inline translation enabled in your application. Try to check inline translation status in stores configuration and disable if needed. Moreover, before sending any email or other customer messages (sms in your case) you need to suspend inline translation to prevent similar issues with improperly enabled inline translation.

public function send($code)

    $this->mySender->send(__('Use that code to verify %1', $code));

  • I disabled the inline translation and it returns only the english string, How to get the translated string? Commented Jan 11, 2017 at 6:51
  • 1
    If you send message from non-customer area(for example admin scope), you need to emulate customer store area for correct translation. Try to inject \Magento\Framework\Locale\ResolverInterface in your sender and call \Magento\Framework\Locale\ResolverInterface::emulate($storeId) before and \Magento\Framework\Locale\ResolverInterface::revert() after sending message.
    – Max
    Commented Jan 11, 2017 at 7:27
  • I have edited the question, Please see above. Commented Jan 11, 2017 at 9:16

You can use sprintf() feature of core PHP

 $messageContent=   sprintf(__('Use that code to verify %s'), $verifyCode);
  • Still the same only get the english string, I think stings translated in the theme layer it may need to be rendered. Commented Jan 10, 2017 at 8:48
  • 1
    you can pass arguments in translate function (__('Use %1 for %2', 'translate', 'translation')). Do not use sprintf for this, incorrect translated string may throw warning in sprintf.
    – Max
    Commented Jan 10, 2017 at 20:33

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.