cancel
Showing results for 
Search instead for 
Did you mean: 

Send Transactional Emails in store language programmatically

Send Transactional Emails in store language programmatically

I have a problem that transactional emails like order comment or shipment comment are sent alsways in english instead of store language.

Tried already a lot with setting areaCodes, StoreIds and so on.

Everytime english even if store 3 (german) is set.

$storeId = 3;
/// Get Website ID
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId); // AREA_ADMINHTML or // AREA_GLOBAL
	
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$websiteId = $storeManager->getWebsite()->getWebsiteId();
$storeManager->setCurrentStore($storeId);

$Order_ID=53;

$order = $objectManager->create('\Magento\Sales\Model\Order')->load($Order_ID);
$comments="Ist versendet";
$orderCommentSender = $objectManager
					  ->create('Magento\Sales\Model\Order\Email\Sender\OrderCommentSender');
$orderCommentSender->send($order, true, $comments);

Any Ideas?

5 REPLIES 5

Re: Send Transactional Emails in store language programmatically

Hello Mobilize,

Please check your html file of mail template and be sure that the string should be inside {{trans}} directive.

{{trans "Thank you for your order from %store_name." store_name=$store.getFrontendName()}}

Also check that the string translation is present in translation csv file and then deploy the static content for that locale. 

For more detail please refer the link

Hope it will help you. Smiley Happy

Re: Send Transactional Emails in store language programmatically

Thank you.
When sending emails from Admin it works translated.
Not so via php..

Re: Send Transactional Emails in store language programmatically

Hola,

 

Tenemos el mismo problema, cuando los emails se envían desde la tienda la traducción funciona, pero cuando lo hacemos mediante programación se envían siempre en inglés.

 

@Mobilize llegaste a solucionarlo? Si es así serías tan amable de compartir la solución, por favor.

 

Gracias!

Re: Send Transactional Emails in store language programmatically

Hello, @Mobilize 

 

We have exactly the same issue. The emails are send correctly translated from the website, but when we create an order programmatically the email with he order resume is send always in english.

 

In case you solved the problem would you be so kind to share the solution with us, please?

 

Thanks!

Re: Send Transactional Emails in store language programmatically

Seems like you need to load translator as it is not there if you trying to sent it programmatically.

$objectManager->get('\Magento\Framework\View\DesignLoader')->load(\Magento\Framework\App\Area::PART_TRANSLATE);

Also if needed you should be able to change language to another one by using localeInterface:

$localeInterface = $objectManager->create('Magento\Framework\Locale\ResolverInterface');
$localeInterface->setLocale('de_DE');
$localeInterface->setDefaultLocale('de_DE');