Magento: wrong translations with external listing on multistore
code, magento, webdev
March 11th 2015 (9 years ago)
One of my clients who has multilanguage(multistore) magento platform wanted to create and save some premade html templates to use them in auction portals.
However, some of data, that should be rendered into the templates has to be properly translated from localized .csv files (i.e. names/titles/etc). As it turnes out simply setting a CurrentStore won’t work.
The translations will be taken from default language.

Solution to the problem

To be able to use properly the __() function, proper Translator needs to be initiated, with proper language code, so the solution will look like that:
require_once '../../app/Mage.php';
Mage::app() -> setCurrentStore(7); // id of the store you need
$currentLocale = Mage::getModel('core/locale') -> getLocaleCode();
Mage::app() -> getLocale() -> setLocale($currentLocale);
Mage::app() -> getTranslator() -> init('frontend', true);
After that, the Translator is initiated with a language of the store with id equals 7 and function __() will behave properly.