10

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?

6 Answers 6

5

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.

3

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
  • 1
    The <action> instruction is deprecated. If the method implementation allows, use the <argument> for <block> or <referenceBlock> to access block public API.
    – TFS
    Aug 3, 2016 at 14:09
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;
}
1

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

'Forgot Your Password'
'Forgot Your Password?'

1
1

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.

3
  • 1
    NO, this is wrong, thumb down, see my answer magento.stackexchange.com/a/134903/23344
    – LucScu
    Feb 23, 2018 at 11:43
  • 1
    This solution worked for me although the text wasn't in the generated output after running bin/magento i18n:collect-phrases -o en_US.csv -m so I had to manually add it (tested in 2.4.4). Jun 3 at 19:27
  • works for me too <head> <title>custom text </title> </head> was translated thank you
    – lazy_coder
    Jun 10 at 13:55
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

1
  • This didn't work @Alex Nov 7, 2019 at 8:51

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.