1

We currently have a multistore Magento 2 set up, we have a custom maintenance page set up using /pub/errors/default/503.phtml, this shows fine when the sites go into maintenance mode, we however want to show a translated message on each page rather than it just being in English. Is this possible?

3
  • please see my below answer. if you want me to work. i will do this. thanks
    – Ashar Riaz
    Nov 20, 2018 at 18:00
  • Updated my answer - it only needs some rewrite rules.
    – sv3n
    Dec 5, 2018 at 14:36
  • Dit it work for you?
    – sv3n
    Feb 28, 2019 at 18:29

2 Answers 2

1

Untested, just quick code check ... and it seems it works the same way as in Magento 1.

By default Magento doesn't support translation out-of-box for error pages, and requires some customizations to allow for such features. So technically there is no proper way to do such.

Since the full stack is NOT initialized during error generation, normal translation functionality $this->__('foobar'); won't work in the templates.

From Translate Maintenance mode per website in multiwebsite-multidomain setup

Maybe you try to adopt the ideas from there ...

Edit:

Magento uses maintenance mode to disable bootstrapping; for example, while you’re maintaining, upgrading, or reconfiguring your site.

https://devdocs.magento.com/guides/v2.2/install-gde/install/cli/install-cli-subcommands-maint.html

Soo its not possible oob ..


Update:

Found another way for translated maintenance page:

  1. In you .htaccess add an rewrite rule that appends a skin parameter to your URL. Eg.

    RewriteCond %{HTTP_HOST} ^french.example.com$
    RewriteCond %{DOCUMENT_ROOT}/var/.maintenance.flag -f
    RewriteCond %{QUERY_STRING} !(^|&)skin=french(&|$) [NC]
    RewriteRule ^ %{REQUEST_URI}?skin=french[L]
    
  2. Copy pub/errors/default to pub/errors/french

  3. Change/translate template files to your needs
-1

yes it is possible. You need to add translation files. First thing you need to do is that in your template file write message like this echo __('Your message').

Then you need to add translation csv files in a new module. Create a new module

lets say it is LanguagePack

Create registration.php inside module

    <?php


\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'yourcompanyname_LanguagePack',
    __DIR__
);

crate module.xml file inside etc folder. LanguagePack/etc/module.xml

 <?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="yourcompanyname_LanguagePack" setup_version="1.0.0">

    </module>
</config>

Then Createfolder i18n inside your module and place all translations files in this folder. for example for french it will be line fr_FR.csv and add french translation against english text.

3
  • Have you tested it for error pages?
    – sv3n
    Nov 20, 2018 at 18:46
  • you need to change location of your maintenance file.
    – Ashar Riaz
    Nov 21, 2018 at 10:36
  • It does not work.
    – sv3n
    Nov 21, 2018 at 13:08

Your Answer

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

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