Magento 2 – What Does `translate=”true”` Do in XML?

localisationmagento2

When I add translate="true" to my XML declarations of my own custom module, will Magento translate them automagically (given that I have the proper i18n CSV files for this)? Or is it only served as a flag for the bin/magento i18n:collect-phrases-command?

For example: I have the following XML file:

<type name="Example\Foo\Model\Foo">
    <arguments>
        <argument name="stuff" xsi:type="array">
            <item name="hello" xsi:type="string" translate="true">Hello World!</item>
        </argument>
    </arguments>
</type>

And the following class:

namespace Example\Foo\Model;

class Foo {
    public function __construct(array $stuff = [])
    {
        var_dump($stuff);
    }
}

Will $stuff['hello'] contain the translated string? Or do I still need to implement my own translation logic and is translate="true" merely a flag used by the collect-phrases-command?

Best Answer

If you have proper i18n then you should set true for translate attribute in XML, (translate="true") else always set false.