12

Translate Maintenance mode per website in multi website-multi domain setup

What is the proper way of translating (localisation) Maintenance page in a multi-website and multi-domain environment?

Setup's made into:

  • MAGENTO_ROOT/index.php
  • MAGENTO_ROOT/uk/index.php
  • MAGENTO_ROOT/us/index.php
  • MAGENTO_ROOT/somecode/index.php

Let's assume that the stores are accesible through:

I can easily see few solutions for it but all of theem seems to be more of a workaround than actual nice, clean solutions.

How do you solve this issue?

1

3 Answers 3

10
+50

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.

Some details on how the error pages are generated can be found on MageBase:

One option is to simply copy errors/ into each of your sub directories of your languages uk, us, etc. and modify the templates to reflect the languages of the website entry point of the end user.

Just note your index.php of each view to include the sub relative errors docs:

if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

Also be aware there is a base template for all errors, including 404 in the page.html

There are probably more elegant solutions but since you are already duplicating index.php for different views, a few more files may not be too much clutter. You could also modify the templates to include the top level CSS and images to save some redundancy.

You could also create a language file the same as you do in Magento's standard localization and read the values in with the process.php file, as title and some other data that would need localization is being set there. A simple example of using Varien_File_Csv to read a language .CSV file:

$csvObject = new Varien_File_Csv();
$csvObject->getData($file);

Additional note: Since the stack at the current point of run time may not allow for the Varien_File_Csv class inclusion using the internal PHP function fgetcsv may be a better alternative.

And parse the language CSV file needed to populate the required data in the process.php file.

Another alternative would be to simply add Google translate or such 3rd party tool to automatically translate the error pages to the end users language.

References:

2

As mentioned before there's no easy way to translate maintenance page. There's one workaround for it however (which has it's own number of advantages/disadvantages) -- use some of the maintenance mode extensions, such as this one:

http://www.magentocommerce.com/magento-connect/store-maintenance.html

It displays maintenance mode page AFTER Magento stack has been loaded, which means that you need to have database connection and few other things. Because of that it's also slower and requires more resources. But if it's not an issue for you, it renders the maintenance page fully customisable.

2
  • What will be the output if i.e. the connection to database will be interrupted?
    – versedi
    Commented Nov 9, 2015 at 6:24
  • 1
    I said, it's workaround and not suitable for every case. If the database is not there Magento will display an error message.
    – Pronto
    Commented Nov 9, 2015 at 18:59
2

Update:

Found another way for translated maintenance page:

https://github.com/OpenMage/magento-lts/blob/1.9.3.x/errors/processor.php#L160-L162

    if (isset($_GET['skin'])) {
        $this->_setSkin($_GET['skin']);
    }

The maintenance page constructor accecpts a skin POST parameter to change layout. It seems to be the intentional way, but it not documentated (yet) ...

  1. Add some rewrite rules to your .htaccess that appends a skin parameter to your URL. Eg.

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

  3. Change/translate template files to your needs

Edit: reomved outdated code, b/c this seems to be correct and will be added to M2 Docs ... https://github.com/magento/devdocs/pull/8247

1
  • This is only for one country. How to translate for multiple country codes Commented Dec 20, 2021 at 6:39

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.