8

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?

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.

| improve this answer | |
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'));
| improve this answer | |
  • 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
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;
}
| improve this answer | |
1

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

'Forgot Your Password'
'Forgot Your Password?'

| improve this answer | |
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

| improve this answer | |
  • This didn't work @Alex – jibin george Nov 7 '19 at 8:51
-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.

| improve this answer | |

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.