7

I don't know if this a bug, but title tag in layout is not translated.

For example,

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Forgot Your Password</title>
    </head>
    <body>....</body>
</page>

Can you confirm if this a bug or not?

4

It still does not seem possible to set a title in the head section and translate it, but you could create a custom customer_account_forgotpassword.xml to fix the issue with this code

<referenceBlock name="page.main.title">
    <arguments>
        <argument name="title" xsi:type="string" translate="true">Forgot Your Password</argument>
    </arguments>            
</referenceBlock>

From Devdocs :

The <action> instruction is deprecated. If the method implementation allows, use the <argument> for <block> or <referenceBlock> to access the block public API.

2

currently it still does not seem possible to set a title in the head section and translate it. There is still an open issue for this bug: https://github.com/magento/magento2/issues/2951

you can actually execute the method setTitle via Layout or in code to set a translated title (like mentioned in the issue):

in Layout:

<referenceBlock name="page.main.title">
    <action method="setPageTitle">
        <argument translate="true" name="title" xsi:type="string">My Dashboard</argument>
    </action>
</referenceBlock>

in code:

$this->pageConfig->getTitle()->set(__('Create New Customer Account'));
  • 1
    The <action> instruction is deprecated. If the method implementation allows, use the <argument> for <block> or <referenceBlock> to access block public API. – Paul Aug 3 '16 at 14:09
  • see my answer, it is the right way magento.stackexchange.com/a/134903/23344 – LucScu Feb 23 '18 at 11:44
2

Magento bug. Add a question mark to match the corresponding entry in your translation file.

'Forgot Your Password'
'Forgot Your Password?'

1

You can also use Factory class

/**
 * @var PageFactory
 */
protected $resultPageFactory;

/**
 * @param Context $context
 * @param PageFactory $resultPageFactory
 */
public function __construct(
    Context $context,
    PageFactory $resultPageFactory
) {
    $this->resultPageFactory = $resultPageFactory;
    parent::__construct($context);
}

public function execute()
{
    /** @var \Magento\Framework\View\Result\Page $resultPage */
    $resultPage = $this->resultPageFactory->create();
    $resultPage->getConfig()->getTitle()->set(__('My Title'));
    return $resultPage;
}
0

In my case it worked just like that.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" layout="1column">
<head>
    <title>Shared products</title>
</head>
<body>
    ...

translation csv file:

"Shared products","Translated title"

Flushed the cache and the translated title showed up immediately. Tested on Magento 2.2.0 in development mode.

0

Need add translate to your theme locale file in i18n.

Seeems bug is in main translate file, where added -

"Contact Us","Kontaktieren Sie uns",module,Magento_Contact

so, will translated in Magento_Contact module.

But header with title - is Magento_Theme module :D

Easy fix - in your theme create directory i18n , file de_DE.csv and put "Contact Us","Kontaktieren Sie uns"

after run php bin/magento setup:upgrade AND php bin/magento cache:flush

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.