Install Linguise automatic translation on Magento

Table of Contents

Magento technical requirements

The neural automatic translation to be used with Magento will require to use the PHP script (can be downloaded below). To install the Linguise script, you’ll need the following requirements:

  • Run PHP 7+
  • Apache, LiteSpeed, NGINX, IIS server
  • Activate the URL rewriting though the Magento configuration
  • Magento 2+

1. Generate the API Key

After your connection to your Linguise dashboard, you’ll need to setup a new domain first and save its settings to get the API Key.

The API key is what is required to activate the translation on your Magento website. Basically, the API key will check what language is activated on what domain and will allow the neural translation pages  to be generated.

Copy the API Key and keep it in your clipboard.

Then by clicking on the tab “Script PHP” you’ll get the installation instructions we’ll follow here in details.

2. Upload and connect the Linguise translation script

The Linguise translation script needs to be uploaded on your server where Magento is installed:

After the script is downloaded, unzip it and upload it to the root folder where the CMS is installed.

  • Make sure it’s at the root level of your website (where your Magento files are located)
  • Make sure the folder keep its default name “linguise”

The Linguise API key will need to be copied in the Configuration.php file you’ve uploaded on your server, edit the file and copy your API Key between the simple quotes, replace the text REPLACE_BY_TOUR TOKEN.

config-php

3. Setup the URLs rewriting

On the admin Sidebar go to Stores > Settings > Configuration > General > Web > Search Engine Optimization and enable the Use Web Server Rewrite option. More information in the official Magento documentation

The URL by language need to be configured in the .htaccess. Just copy this code after the code RewriteEngine onavailable in the default Magento 2 .htaccess. 

				
					<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-cn|zh-tw|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu|zz-zz)(?:$|/)(.*)$ linguise/linguise.php?linguise_language=$1&original_url=$2 [L,QSA]
</IfModule>
				
			

Finally, your Magento .htaccess should look something like this:

4. Activate the language switcher

4.1 Load the Linguise JS script

You can now load all your translated pages using the URL, for example: www.shop.com/fr/

The language switcher is the flag popup to select the language you want. To load it, you’ll need to copy the code given at the end of the website configuration to the head of your HTML page. The flag language switcher will then be loaded automatically.

It needs to be loaded in your page header. Magento 2 gives you the ability to add content in the head of your page through the configuration.

In the admin panel go to Content > Configuration, edit your default store theme view, then click on HTML Head section and add the copied script to the Scripts and Style Sheets input. Finally, save the configuration.

4.2 Install the Magento security module

Since Magento 2.3.5 you need to add a security module to allow Magento to load files from Linguise domain. If you’re familiar with Magento that won’t be a problem, otherwise here is a step-by-step guide:

  1. Download the module from this link
  2. Unzip the content of the zip into your Magento installation in the directory app/code/
  3. Then run the commands:
				
					php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:clean
				
			

The language switcher will be displayed by default in a floating top right position on your website. You are welcome to customize it as you wish with CSS.

Activate local cache system

As an option, you can activate a local cache system that stores URLs and its related multilingual content to serve the pages faster. The local cache will save some data transfer between Linguise server and your website server. The cache is used only when a page has already been translated and has not been updated. The cache kept in priority will be the cache from the most viewed multilingual pages.

As an option, you can define the amount of cache stored in MB. In the following example the cache is activated and the amount of cache to keep is 500MB:

				
					    /** Basic configuration **/
    public $cache_enabled = true;
    public $cache_max_size = 500; // In megabyte