문제

I need to create multilingual static block. So far I have created static block with id 'delivery_returns'.

I'm calling it in catalog\product\view.phtml like this:

$deliveryBlock = Mage::getModel('cms/block')->load('delivery_returns');
echo $deliveryBlock->getTitle();
echo $deliveryBlock->getContent();

I understand that to translate this block:

  1. I should just create another one.
  2. Choose my desired language from store_view field
  3. and keep the static block identifier same as original.

This method works with 'footer_links' and also with another static block I made, called 'header_links', but apparently it is not working with 'delivery_returns' block. Changing store language does not load corresponding translated 'delivery_returns' block

What am I missing? Is there a better way to achieve this?

도움이 되었습니까?

해결책

  1. Create a static block for each language, all with the same identifier.
  2. Render the block with the cms/block block. It will automatically add the store ID to load the correct version of the block.

Here's an easy way to load and render the block directly in the template file:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('delivery_returns')->toHtml() ?>

Alternatively, declare the block in a layout file and render it with <?php echo $this->getChildHtml('delivery_returns') ?>:

<block type="cms/block" name="product.delivery_returns" as="delivery_returns">
    <action method="setBlockId"><block_id>delivery_returns</block_id></action>
</block>

다른 팁

The answer below talks about setting the store id prior to loading the model, but, as @benmarks noted in the comment below, this is unnecessary, as that happens in the block's _toHtml().

As with many other mage models, try setting the desired store id before loading the model:

$deliveryBlock = Mage::getModel('cms/block')
                     ->setStoreId(Mage::app()->getStore()->getId())
                     ->load('delivery_returns');

echo $deliveryBlock->getTitle();

/**
 * You shouldn't print the content directly (although I'm assuming it's for debugging purposes only).
 * Use the code below, so as the possible content directives (the "{{ }}" thingies) would be interpreted.
 * Check out Mage_Cms_Block_Block::_toHtml().
 */
echo Mage::helper('cms')->getBlockTemplateProcessor()
                        ->filter($deliveryBlock->getContent());

I've accomplished this in one of a few ways:

  1. Just use a different static block name, copy and translate, and refer to it in your theme separately.
  2. You can use `{{translate text="text to translate"}} in any cms, static block page by implementing the following workaround:

    • copy app/code/core/Mage/Core/Model/Email/Template/Filter.php to app/code/local/Mage/Core/Model/Email/Template/Filter.php and modify the following:

--

public function translateDirective($construction)
{
    $params = $this->_getIncludeParameters($construction[2]);
    $text = $params['text'];
    return Mage::helper('page')->__($text);
} 

More information/source:

http://jagdeepbanga.com/blog/magento_how_add_translation_ability_into_cms_page_or_static_block.html

You can download a module i created based on this answer from here: https://github.com/miguelbalparda/MB_Translate/ It makes available the inline translator of Magento in CMS/Block pages.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top