Showing results for 
Search instead for 
Did you mean: 

How to translate <title>

How to translate <title>



For contact page, this is in the layout definition file (contact_index_index.xml):


        <title>Contact Us</title>

That title is not translated.How can it be translated? is it a bug in Magento2?




Tags (2)

Re: How to translate <title>

Do you have the "Contact Us" entry in your language package?

Re: How to translate <title>

Of course, and in fact, if I add <?php /* @escapeNotVerified */ echo __('Contact Us') ?> to phtml file, it is translated correctly. I have even added a breadcrumb to this layout with:


<page xmlns:xsi="" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceContainer name="content">
            <referenceBlock name="breadcrumbs">
                <action method="addCrumb">
                    <argument name="crumbName" xsi:type="string">Home</argument>
                    <argument name="crumbInfo" xsi:type="array">
                        <item name="title" xsi:type="string" translate="true">Home</item>
                        <item name="label" xsi:type="string" translate="true">Home</item>
                        <item name="link" xsi:type="string">/</item>
                <action method="addCrumb">
                    <argument name="crumbName" xsi:type="string">Contact Us</argument>
                    <argument name="crumbInfo" xsi:type="array">
                        <item name="title" xsi:type="string" translate="true">Contact Us</item>
                        <item name="label" xsi:type="string" translate="true">Contact Us</item>

And text is translated correctly. The problem is in head element.


Another fact. Both the page title shown for browser window and page title shown above the breadcrumb are not translated.




Re: How to translate <title>

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`:



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 `etc/frontend/di.xml` file:


<preference for="Magento\Framework\View\Page\Config\Renderer" type="Company\Module\Model\Page\Renderer" />