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?
2 Answers
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:
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]
Copy
pub/errors/default
topub/errors/french
- Change/translate template files to your needs
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.