我有默认 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/