Magento : How add translation ability into cms page or static block
As we all know magento have multi-language store. If you want to run a multi-languages site, you may face a necessity to create separate version of every static block or CMS page for every shop view (language). It may be rather time consuming process. It would be great to have something like __(“Text to translate”) for the CMS pages.
Magento use following syntax in .pthml to make text translate to multi-language which is like this :
<?php echo $this->__('text to translate'); ?>
OR
<?php echo Mage::helper('ModuleName')->__('text to translate'); ?>
But text written in cms page or static block have not translation ability.
To make CMS page or static block text compatible with translation ability we need to do some extra coding work which is like this:
We can use following directive in cms page or static block
{{translate text=”text to translate”}}
To make it working in cms page or static block we need to add directive function in magneto code as show in following steps.
1. Go to app/code/core/Mage/Core/Model/Email/Template/ and download Filter.php file
2. open Filter.php and add following function after function mediaDirective()
public function translateDirective($construction) { $params = $this->_getIncludeParameters($construction[2]); $text = $params['text']; return Mage::helper('page')->__($text); }
3. Save file.
4. Next upload Filter.php in new custom location : app/code/local/Mage/Core/Model/Email/Template/
5 Now you can easily use following directive in any cms page or static block.
{{translate text="text to translate"}}
That’s it.