Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate from DI does not seem to work #9411

Closed
romainruaud opened this issue Apr 26, 2017 · 1 comment
Closed

Translate from DI does not seem to work #9411

romainruaud opened this issue Apr 26, 2017 · 1 comment
Assignees
Labels
bug report Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed non-issue

Comments

@romainruaud
Copy link
Contributor

romainruaud commented Apr 26, 2017

Preconditions

  1. Magento CE 2.1.6

Steps to reproduce

  1. I have a module defining this :
class MyClass extends \Magento\Framework\View\Element\Template
{
    /**
     * @var array
     */
    private $rendererList;

    /**
     * Constructor.
     *
     * @param \Magento\Framework\View\Element\Template\Context $context      Block context
     * @param array                                            $data         The data
     * @param array                                            $rendererList The renderers used for autocomplete rendering
     */
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        array $data,
        array $rendererList = []
    ) {
        $this->rendererList = $rendererList;

        parent::__construct($context, $data);
    }

and the DI :

    <type name="Vendor\Block\XXXXX\MyClass">
        <arguments>
            <argument name="rendererList" xsi:type="array">
                <item name="term" xsi:type="array">
                    <item name="title" xsi:type="string" translate="true">Search terms</item>
                </item>
            </argument>
        </arguments>
    </type>

Notice the translate="true" for the title.

  1. I add a log to the $rendererList variable
  2. I add a translation for "Search terms" string into "Terms de recherche"
  3. My front is properly configured with the proper locale

Expected result

(
    [term] => Array
        (
            [title] => Termes de recherche
        )
)

I was expecting to see the translated string.

Actual result

(
    [term] => Array
        (
            [title] => Search terms
        )
)

So for me the translate="true" in the DI is getting ignored, or maybe am I using it wrongly ?

@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Oct 4, 2017

@romainruaud Thanks for reporting this issue.
Di.xml used for Object Manager configuration to create objects. It should not be used for translation of any kind. Therefore since Magento 2.2.0 attribute 'translate' was removed from di.xml.
Logic for translation should be on presentation layer, not configuration one. So, if You want translation occur, You should move translation logic in template - some_template_for_your_block.phtml for instance.
If you'd like to update it, please reopen the issue.

@magento-engcom-team magento-engcom-team self-assigned this Oct 4, 2017
@magento-engcom-team magento-engcom-team added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed non-issue labels Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed non-issue
Projects
None yet
Development

No branches or pull requests

3 participants