【问题标题】:Magento: how to translate action tag content?Magento:如何翻译动作标签内容?
【发布时间】:2011-12-06 20:48:54
【问题描述】:

我有默认 page.xml。

我已经添加了

<block type="core/text" name="for_everyone">
   <action method="setText" translate="text"><text>Some text!</text></action>
</block> 

<block type="core/text_list" name="content" as="content" translate="label">
    <label>Main Content Area</label>
</block>

我得到了这个:

<block type="core/text_list" name="content" as="content" translate="label">
    <label>Main Content Area</label>
    <block type="core/text" name="for_everyone">
        <action method="setText" translate="text"><title>Some text!</title></action>
    </block> 
</block>

然后我为我的主题添加了两个文件:

app/design/frontend/default/default/locale/en_US/translate.csv

"Some text!","Some text!"

app/design/frontend/default/default/locale/fr_FR/translate.csv

"Some text!","un text!"

但每次我运行任何语言时,我都会看到“一些文本!”。同时为网站选择的语言使用正确。例如,catalog.xml 中的字符串完美翻译:

<block type="core/template" name="right.permanent.callout" template="callouts/right_col.phtml">
      <action method="setImgSrc"><src>images/media/col_right_callout.jpg</src></action>
      <action method="setImgAlt" translate="alt" module="catalog"><alt>Keep your eyes open for our special Back to School items and save A LOT!</alt></action>
</block>

我也尝试过使用类似的东西和其他标签:

<action method="setText" translate="title"><text>Some text!</title></action>

有人知道问题出在哪里吗?

【问题讨论】:

    标签: magento-1.5 magento


    【解决方案1】:

    translate 属性应包含以空格分隔的要翻译的标记名称列表。例如,如果传递给Mage_Core_Block_Text::setText() 的参数一被封装在`node 中,您应该具有以下内容:

    <action method="setText" translate="foo"><foo>Some text!</foo></action>
    

    除非尝试通过布局 XML 传入数组结构,否则参数节点名称无关紧要。

    另外值得注意的是,如果设置了module 属性,则该字符串将被传递给辅助类工厂方法(Mage::helper() - 请参见下面的时间线)。对于出现不正确翻译的情况,请确认 core_translate 数据库表中没有覆盖条目,只有在使用内联翻译时才会输入。

    调用顺序:

    • Mage_Core_Controller_Varien_Action::loadLayout()
      • ::generateLayoutBlocks()
        • Mage_Core_Model_Layout::generateBlocks()
          • ::_generateBlocks()
            • ::_generateAction()
              • ::_translateLayoutNode()

    处理&lt;action /&gt;指令的翻译属性的是_translateLayoutNode()

    if (isset($node['module'])) {
        $args[$arg] = Mage::helper((string)$node['module'])->__($args[$arg]);
    }
    else {
        $args[$arg] = Mage::helper('core')->__($args[$arg]);
    }
    

    【讨论】:

    • 谢谢!您能否提供一些类工厂方法的示例或链接。我的意思是 module="smth" 是如何工作的。
    • 对于嵌套块使用点如translate="foo.bar" 将翻译&lt;foo&gt;&lt;bar&gt;Some text!&lt;/bar&gt;&lt;/foo&gt;
    【解决方案2】:

    检查您的 locale 文件夹的名称(尾随 e)

    app/design/frontend/default/default/local/en_US/translate.csv
    app/design/frontend/default/default/locale/en_US/translate.csv
    

    【讨论】:

    • 对不起,我在这里输入时收到了。修好了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 2012-04-20
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    相关资源
    最近更新 更多