Magento: how to translate action tag content?

2020-07-20 03:32发布

问题:

I have default page.xml.

I have added

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

to

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

and I got this one:

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

Then I added two files for my theme:

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

"Some text!","Some text!"

and

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

"Some text!","un text!"

But every time I run any language I see "Some text!". At the same time selected lang for website is used correct. For example the string from catalog.xml translates perfect:

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

I also tried to use smth like that and other tags:

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

Does anybody know what the problem is?

回答1:

The translate attribute should contain a space-delimited list of tag names to translate. For example, if the argument one is passing to Mage_Core_Block_Text::setText() is encapsulated in ` node, you should have the following:

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

Unless one is trying to pass in an array structure via layout XML, argument node names do not matter.

Also worth noting is that if one sets the module attribute, that string will be passed to the helper class factory method (Mage::helper() - see timeline below). For instances where incorrect translation is being seen, verify that there are no overriding entries in the core_translate database table, which would only be entered if inline translation has been used.

Call sequence:

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

It is _translateLayoutNode() which processes the translate attributes of the <action /> directives:

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


回答2:

Check the name of your locale folder (trailing e)

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