Global translations in PrestaShop

A custom implementation to define translations that can be used in different PrestaShop theme templates and modules.

Global translations in PrestaShop

As you probably know if you are reading this, when using translations to different languages in PrestaShow their scope is just a single template (if they’re in a theme) or a single module (if they’re in a custom module). So… what if you want to create global translations which can be used in different templates and modules, and therefore avoid duplicated content and make maintenance easier? It seems there’s no native way to define them, so let’s try this implementation.

This is the solution I have implemented in my own site:

  1. Create a new .tpl template file under your theme path; I’m using /themes/themename/0globaltrans.tpl so as it appears at the top in the list of translations in PrestaShop’s backend (admin interface).
  2. Insert this code in the previous file:
    List all possible translations below
    in order to make them appear in PrestaShop back office:
    {l s="string to translate 1"}
    {l s="string to translate 2"}
    {l s="string to translate 3"}
    {l s=$s}
  3. In every template (.tpl file) where you want to insert these global translations, use this code instead of {l s="string to translate 1"}:
    {include file="$tpl_dir./0globaltrans.tpl" s="string to translate 1"}
  4. Now we can manage these translations from the PrestaShop back office, through Localization > Translations > Front office translations. If you have used  the suggested file name for the global template, they will appear under the section 0GLOBALTRANSGlobal translations in PrestaShop's back office

How does it work?

Instead of using the usual function {l s="... , we include the global file passing the string to translate as a variable; in the included file we just take that variable and call the translation function. Since all the translations are called from the same .tpl file, they will appear all in the same section in PrestaShop’s translation tool in the back office.

We have to list all the translated strings in the top commented block; otherwise they don’t appear in the back office (at least in version 1.6).

Does it work for you? Any other functionality you would need?

One thought on “Global translations in PrestaShop

  1. dr0n3


    Nice article you got here.

    I know how to access and reuse translated prestashop module fields like:

    $mod = Module::getInstanceByName(‘module_name’);
    echo $mod->l(‘translated field’);

    But how to access the main translation file in pubic_html/themes/your_theme/lang/two_digit_iso_lang_code.php
    to get the content with l(); method from a module in PHP?

Leave a Reply

Your email address will not be published. Required fields are marked *