3

i have to load magento in a cms and want to include the complete header. Everything works fine, but i don't get the right translation of the template. The locale setting of the store view is correct.

require_once 'app/Mage.php';
Mage::app()->setCurrentStore('de');

$layout = Mage::app()->getLayout();
$layout->getUpdate()->addHandle('default')->load();
$layout->generateXml()->generateBlocks();

echo $layout->getBlock('header')->toHtml();

1 Answer 1

4

You can try to emulate the store:

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

The code between start/stopEnvironmentEmulation should just work as within Magento.

The cool thing is, that startEnvironmentEmulation() also takes care of the locale with the following line from Mage_Core_Model_App_Emulation:

$initialLocaleCode = $this->_emulateLocale($storeId, $area);

Otherwise you can just try to emulate the locale like this:

Mage::app()->getLocale()->emulate($storeId());

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.