magento-1.5 - Magento:如何翻译 Action 标签内容?

标签 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!"

但每次我运行任何语言时,我都会看到“一些文本!”。同时为网站选择的语言使用正确。例如,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>

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

最佳答案

translate属性应包含以空格分隔的要翻译的标记名称列表。例如,如果参数 one 传递给 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]);
}

关于magento-1.5 - Magento:如何翻译 Action 标签内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8406631/

相关文章:

magento - 我如何在 magento 的自定义模块中设置配置示例数据

magento - 为什么我的新付款方式没有显示在 Magento 的单页结帐中?

php - Magento 商店 - 将 nofollow 添加到分层导航

magento - 网格没有出现在 Magento 的自定义管理模块中

Magento 1.12 和 Solr 3.6 没有正确的结果,也没有拼写建议

magento-1.4 - 如何向 Magento 中的所有页面添加 cms 静态 block ?

php - Magento:更改配置选项而不保存

.htaccess - Magento <IfVersion',可能拼写错误或由未包含在服务器配置中的模块定义

mysql - 如何更新 MySQL 中的到期日期?

php - 使用 Tinybrick 的 Lightspeed 进行高级打洞