Magento:如何翻译动作标签内容?

时间:2011-12-06 20:48:55

标签: magento-1.5 magento

我有默认的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!"

但每次我运行任何语言时,我都会看到“有些文字!”。同时选择lang for website使用正确。例如,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>

我也试过像那样和其他标签使用smth:

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

有人知道问题是什么吗?

2 个答案:

答案 0 :(得分:8)

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()

_translateLayoutNode()处理<action />指令的翻译属性:

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

答案 1 :(得分:2)

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

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