3

Here I have the default contact page layout file (contact_index_index.xml):

<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>Contact Us</title>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml">
                <container name="form.additional.info" label="Form Additional Info"/>
            </block>
        </referenceContainer>
    </body>
</page>

How can I translate the head title?

3 Answers 3

2

contact_index_index.xml

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

Reference: /vendor/magento/module-customer/view/frontend/layout/customer_account_index.xml

1

I use the following fix for this bug. You have to override Magento 2 Page renderer. Create a model file in your module Company/Module/Model/Page/Renderer.php:

<?php


namespace Company\Module\Model\Page;

class Renderer extends \Magento\Framework\View\Page\Config\Renderer {

    /**
     * @return string
     */
    public function renderTitle()
    {
        return '<title>' . $this->escaper->escapeHtml(__($this->pageConfig->getTitle()->get())) . '</title>' . "\n";
    }
}

And then add the following line to the Copmany/Module/etc/frontend/di.xml file:

<preference for="Magento\Framework\View\Page\Config\Renderer" type="Company\Module\Model\Page\Renderer" />
1
  • Thanks man. This is the only solution that worked for me.
    – Nayem323
    Commented Jul 31, 2019 at 10:46
0

In your custom theme, overwrite the page title in this layout file: 'app/design/frontend/VENDOR/YOURTHEME/Magento_Contact/layout/contact_index_index.xml'

<?xml version="1.0"?>
<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>Kontakt</title>
    </head>
</page>
1
  • Your code do overwrite title, but it does not translate it so if you change your locale it will stay 'kontakt'
    – Dynomite
    Commented Mar 9, 2017 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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