[SOLVED] Magento 1.9 BUG FIX Cron email alerts sent in wrong language

I found a Magento bug which makes cron (price, stock) alerts emails being in the wrong language.

Issue

I have configured price alerts for a client (which originally registered into my shop with spanish language).

The user receives the email, but it is in english.

For instance, the text: “You are receiving this notification because you subscribed to receive alerts when the prices for the following products changed:” (in ./app/design/frontend/base/default/template/email/productalert/price.phtml) is not being translated to spanish.

I have checked and the translation is present in ./app/locale/es_ES/Mage_ProductAlert.csv: “You are receiving this notification because you subscribed to receive alerts when the prices for the following products changed:”,”Usted está recibiendo esta notificación porque está suscrito para recibir alertas cuando los precios de los siguientes productos cambien:”

I am using a custom theme.

I have also tried to add that translation to my theme: app/design/frontend/mytheme/default/locale/es_ES/translate.csv

I have flushed translations cache and deleted Magento cache. Still not being translated.

Fix

What I did to fix the issue:

Edit app/code/core/Mage/ProductAlert/Model/Email.php

Replace this (line 255):

       $appEmulation = Mage::getSingleton('core/app_emulation');
       $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);

With this:

        $appEmulation = Mage::getSingleton('core/app_emulation');
        $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
        //Dealing with uninitialized translator!
        Mage::app()->getTranslator()->init('frontend', true);

Flushed the cache and voila! Now magento is sending the email alerts in the right language 🙂