I have Magento 2.4.6-p1 running on PHP 8.1.20 and the email messages associated with Product Alerts are not translated. I have a multilingual store with 7 locales and I have successfully translated every text related with both Magento core modules and 3rd party modules except from Product Alert messages. I have verified that the appropriate texts are found in the i18n/CSV files.
This must be a bug of Magento and not some problem related with my own Magento installation.
Solved! Go to Solution.
It seems that the problem with translating the emails associated with product alerts has been identified for Magento 2.4.7:
https://github.com/magento/magento2/tree/2.4.7-beta1/app/code/Magento/ProductAlert
At the updated Product Alert module, I noticed that only the file app/code/Magento/ProductAlert/Model /Mailing/AlertProcessor.php has changed. I tried the updated Product Alert module, but unfortunately the problem with translations persisted. Of course, Magento 2.4.7 is still in beta phase, so maybe the problem is fixed till version 2.4.7 becomes stable.
Anyway, based on directions below:
https://github.com/magento/magento2/issues/35674
I created and applied the below patch and tested it on Magento 2.4.6-p1 running PHP 8.1.20, and it worked without any errors recorded in the log files:
diff --git a/vendor/magento/module-product-alert/Model/Email.php b/vendor/magento/module-product-alert/Model/Email.php index 379ae29..c6b1c12 100644 --- a/vendor/magento/module-product-alert/Model/Email.php +++ b/vendor/magento/module-product-alert/Model/Email.php @@ -31,6 +31,7 @@ use Magento\Store\Model\App\Emulation; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Store\Model\Website; +use Magento\Framework\App\AreaList; /** * ProductAlert Email processor @@ -139,6 +140,11 @@ class Email extends AbstractModel */ protected $_customerHelper; + /** + * @var View + */ + protected $areaList; + /** * @param Context $context * @param Registry $registry @@ -149,6 +155,7 @@ class Email extends AbstractModel * @param View $customerHelper * @param Emulation $appEmulation * @param TransportBuilder $transportBuilder + * @param AreaList $areaList; * @param AbstractResource $resource * @param AbstractDb $resourceCollection * @param array $data @@ -164,6 +171,7 @@ class Email extends AbstractModel View $customerHelper, Emulation $appEmulation, TransportBuilder $transportBuilder, + AreaList $areaList, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = [] @@ -175,6 +183,7 @@ class Email extends AbstractModel $this->_appEmulation = $appEmulation; $this->_transportBuilder = $transportBuilder; $this->_customerHelper = $customerHelper; + $this->areaList = $areaList; parent::__construct($context, $registry, $resource, $resourceCollection, $data); } @@ -346,7 +355,9 @@ class Email extends AbstractModel $storeId = (int) $this->getStoreId() ?: (int) $this->_customer->getStoreId(); $store = $this->getStore($storeId); - $this->_appEmulation->startEnvironmentEmulation($storeId); + $this->_appEmulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true); + $area = $this->areaList->getArea(\Magento\Framework\App\Area::AREA_FRONTEND); + $area->load(\Magento\Framework\App\Area::PART_TRANSLATE); $block = $this->getBlock(); $block->setStore($store)->reset();
It seems that the problem with translating the emails associated with product alerts has been identified for Magento 2.4.7:
https://github.com/magento/magento2/tree/2.4.7-beta1/app/code/Magento/ProductAlert
At the updated Product Alert module, I noticed that only the file app/code/Magento/ProductAlert/Model /Mailing/AlertProcessor.php has changed. I tried the updated Product Alert module, but unfortunately the problem with translations persisted. Of course, Magento 2.4.7 is still in beta phase, so maybe the problem is fixed till version 2.4.7 becomes stable.
Anyway, based on directions below:
https://github.com/magento/magento2/issues/35674
I created and applied the below patch and tested it on Magento 2.4.6-p1 running PHP 8.1.20, and it worked without any errors recorded in the log files:
diff --git a/vendor/magento/module-product-alert/Model/Email.php b/vendor/magento/module-product-alert/Model/Email.php index 379ae29..c6b1c12 100644 --- a/vendor/magento/module-product-alert/Model/Email.php +++ b/vendor/magento/module-product-alert/Model/Email.php @@ -31,6 +31,7 @@ use Magento\Store\Model\App\Emulation; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Store\Model\Website; +use Magento\Framework\App\AreaList; /** * ProductAlert Email processor @@ -139,6 +140,11 @@ class Email extends AbstractModel */ protected $_customerHelper; + /** + * @var View + */ + protected $areaList; + /** * @param Context $context * @param Registry $registry @@ -149,6 +155,7 @@ class Email extends AbstractModel * @param View $customerHelper * @param Emulation $appEmulation * @param TransportBuilder $transportBuilder + * @param AreaList $areaList; * @param AbstractResource $resource * @param AbstractDb $resourceCollection * @param array $data @@ -164,6 +171,7 @@ class Email extends AbstractModel View $customerHelper, Emulation $appEmulation, TransportBuilder $transportBuilder, + AreaList $areaList, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = [] @@ -175,6 +183,7 @@ class Email extends AbstractModel $this->_appEmulation = $appEmulation; $this->_transportBuilder = $transportBuilder; $this->_customerHelper = $customerHelper; + $this->areaList = $areaList; parent::__construct($context, $registry, $resource, $resourceCollection, $data); } @@ -346,7 +355,9 @@ class Email extends AbstractModel $storeId = (int) $this->getStoreId() ?: (int) $this->_customer->getStoreId(); $store = $this->getStore($storeId); - $this->_appEmulation->startEnvironmentEmulation($storeId); + $this->_appEmulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true); + $area = $this->areaList->getArea(\Magento\Framework\App\Area::AREA_FRONTEND); + $area->load(\Magento\Framework\App\Area::PART_TRANSLATE); $block = $this->getBlock(); $block->setStore($store)->reset();