We used cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. What For?

« Back to Blogs

Custom Texts Translation in Prestashop 1.7.6

Prestashop custom texts

PrestaShop is a very popular freemium, open source e-commerce solution. It is written in the PHP programming language with support for the MySQL database management system making it easier to integrate easily with multiple platforms.

Prestashop provides a multilingual translation tool for the shop. This helps to add and edit the translations in multiple languages for the pages and content.

Sometimes we need to do customizations related to the texts and designs in the theme and shop as per our requirements. Therefore, if our shop is multilingual then we are required to add translations for our custom texts also. But translation for the custom texts in the classic theme is different from the other themes.

The classic theme does not directly provide translation for the custom texts as it uses different domains and translation. Further, it also uses an unique id to translate the strings used in modules, templates, and controllers.

Here is a way to translate the custom texts in classic theme in Prestashop 1.7.6 version.

Step 1: [Database Level] Add the custom texts in table ps_translation as below.

Description:
     INSERT INTO ps_translation VALUES(id_translation,id_lang,key,translation,domain,theme);
     Where,
         id_translation : auto-increment field.
         id_lang : default language id (eg.: 1 for English)
         key : text to be translated.
         translation : translation of the key in the default language.
         domain : used in translation to uniquely identify the texts [should be single text without dot(.) operator].
         theme : theme name in which text is written.

Example: Text:- { l s=’My Text’ d=’Shop.Customtext’’ } here, d stands for the domain.
                 [Note:- Domain name for the theme should start with Shop, for modules should start with Modules and for the admin panel it should start with Admin.]

Step 2: After insertion in database export the language from Prestashop back office as follows:
  • Login into the admin panel.
  • Go to International -> Translation -> Export a language
    • Under this select default language (eg. English).
    • Select the theme in which you want translation (eg. classic)
  • Then click on the Export button.
  • After exporting, a zip will be downloaded. Then extract that zip. There will be two files.
    • One will be a lang file like “en-US.en-US.xlf”.
    • Another will be translation file (named with domain stored in translation table eg. ShopCustomtext.en-US.xlf)
Step 3:- Now, we will need to change the file path, source, and target language in the extracted translation file.
  • Open the translation file having domain name eg. ShopCustomtext.en-US.xlf.
  • Here you will get all the text that has been added in the database ps_translation table for translation.
  • Now change the original path in the <file> element with the path and line number where that text has been written in Prestashop files.
  • Now change the source-language and target-language in element with default lang id such as ‘en’.
  • In the same way, differentiate all the text as per their locations in files in Prestashop.
  • Next save this file and make two copies of it and name them as below eg:
    • ShopCustomtext.en-US.xlf [original]
    • ShopCustomtext.xlf [copy]
    • ShopCustomtext.fr-FR.xlf [French translation copy. You can rename with any language which you want for translation]
  • Moving on, put the original one that is ShopCustomtext.en-US.xlf inside all the translation folders for en language.
  • Now in the second copy i.e. ShopCustomtext.xlf, change the source language as ‘en-US’ at every place and put it inside the default folder of translations.
  • Now in the third copy i.e. ShopCustomtext.fr-FR.xlf, change the target language and element text in which language you want to translate it (here it will be in French).
  • Now save this above file and put it inside all the translation folders for fr language.
Step 4: Check the translation in the back office for the Custom domain.
  • Login in to the admin panel.
  • Go to International -> Translation -> Modify Translations
    • Select the type of translation as Theme translation.
    • Select language for translation such as French.
  • Then click on the Modify button.
  • Now go to the Shop section in which you can see your domain name such as Customtext which has all text with their translations.
  • Now save this translation by clicking on the Save button.
Step 5: Check the Front office by translating the language.

All the custom text will be now translated from English to French and vice versa.


We hope this translation guide was helpful to you. We try to post such helpful guides on various technologies regularly on our blog. Check out our other blog posts, bookmark us and of course feel free to leave any comments. And while you are at it, if you need any help with deployment of Open source solutions check out the services.

contact-us Request a callback WhatsApp