~欢迎来到*秋の网*部落格 Welcome to Chew's Web blog~ 使用火狐会更好 Download Best view using Mozilla Firefox. Download

Thursday, July 31, 2014

Magento: Add translation ability into a static block or CMS page

on CMS page or static block, will be able to use {{translate text="A text to translate to your current locale"}}

app/etc/modules/Package_Widget.xml
xml version="1.0"?>
<config>
    <modules>
        <Package_Widget>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Widget/>
            </depends>
        </Package_Widget>
    </modules>

</config>


app/code/local/Package/Widget/etc/config.xml
xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <Package_Widget>
            <version>0.1.0</version>
        </Package_Widget>
    </modules>
    <global>
        <models>
            <widget>
                <rewrite>
                    <template_filter>Package_Widget_Model_Template_Filter</template_filter>
                </rewrite>
            </widget>
        </models>
    </global>

</config>


app/code/local/Package/Widget/Model/Template/Filter.php

class Package_Widget_Model_Template_Filter extends Mage_Widget_Model_Template_Filter
{
    /**
     * Directive for translating tex using current locale
     * Supported options:
     *     text - text to translate
     *
     * @param array $construction
     * @return string
     */
    public function translateDirective($construction)
    {
        $params = $this->_getIncludeParameters($construction[2]);

        $text = $params['text'];
        
        return Mage::helper('core')->__($text);
    } 

}

copy app/code/core/Mage/Core/Model/Email/Template/Filter.php to
app/code/local/Mage/Core/Model/Email/Template/Filter.php
and paste the code below mediaDirective()

     /**
     * Directive for translating tex using current locale
     * Supported options:
     *     text - text to translate
     *
     * @param array $construction
     * @return string
     */
    public function translateDirective($construction)
    {
        $params = $this->_getIncludeParameters($construction[2]);

        $text = $params['text'];
        
        return Mage::helper('core')->__($text);
    } 


0 comments:

秋の网 - 赵のchew © 2009 - 2012. Leave me comment, I will reply u as soon as possible.