Table of contents

Translations in PrestaShop 1.5

PrestaShop has several types of translations:

For each type of translation, PrestaShop's internal translation tool parses a specific set of folders in order to retrieve all the translatable strings it contains, and present them to the translator.

Front-office translations

The following folders are parsed:

The translatable strings use the following Smarty syntax:

{l s='There are no products in this category.'}

Two options can be added to this syntax:

All the front-end translations are stored in the following file, with iso_code being the ISO 3166-1 code (http://www.iso.org/iso/country_codes.htm) for the language of the translated strings (de, fr, en, it, es, etc.):

The translations are stored in a PHP array, named $_LANG, and take the following form, using an MD5 of the string:

The identification key is built by combining the name of the template file from which the string comes, an underscore, and the MD5 hash of the string itself.

If the same string appears in several different controllers, it will appear as many times in the translation tool.

On the other hand, if one string appears in both a controller and its template, it will only appear once for this controller.

Back-office translations

The following folders are parsed:

The translatable strings use the following syntaxes:

Three options can be added to these syntaxes:

All the back-end translations are stored in the following file, with iso_code being the ISO 3166-1 code (http://www.iso.org/iso/country_codes.htm) for the language of the translated strings (de, fr, en, it, es, etc.):

The translations are stored in a PHP array, named $_LANGADM, and take the following form:

The identification key is built by combining the name of the controller from which the original string comes and the MD5 hash of the string itself.

Note that:

If the same string appears in several different controllers, it will appear as many times in the translation tool.

On the other hand, if one string appears in both a controller and its template, it will only appear once for this controller.

Error messages translations

The following folders are parsed:

The translatable strings use the following syntax:

Tools::displayError('An error occurred while creating archive.')

By default, the string goes through the htmlentities() function, in order to convert special characters to HTML entities on the fly. You can specify that htmlentities() should not be used by adding a final option:

Tools::displayError('An error occurred while creating archive.', false)

This method must not be used within modules, because then the string translations would be saved in the /translations/iso_code/errors.php file instead of the /modules/name_of_the_module/translations/iso_code.php file.

All the error messages translations are stored in the following file, with iso_code being the ISO 3166-1 code (http://www.iso.org/iso/country_codes.htm) for the language of the translated strings (de, fr, en, it, es, etc.):

The translations are stored in a PHP array, named $_ERRORS, and take the following form:

The identification key is built using the MD5 hash of the string itself.

If one string appears in several different files, it will only appear once in the translation tool.

Field names translation

The following folder is parsed:

The string are those returned by the getValidationRules() method from ObjectModule for each class.

All the field names translations are stored in the following file, with iso_code being the ISO 3166-1 code (http://www.iso.org/iso/country_codes.htm) for the language of the translated strings (de, fr, en, it, es, etc.):

The translations are stored in a PHP array, named $_FIELDS, and take the following form:

The identification key is built by combining the name of the class from which the string comes, an underscore, and the MD5 hash of the string itself.

Installed module translations

When in production mode, only the currently installed modules can be translated. If you wish translate all modules, whether installed or not, you must put your installation of PrestaShop in "debug" mode.

The following folder is parsed:

The translatable strings use the following syntax:

Three options can be added to these syntaxes:

The Tools::displayError() method must not be used within modules, because then the strings' translations would be saved in the /translations/iso_code/errors.php file instead of the modules/name_of_the_module/translations/iso_code.php file.

Since PrestaShop 1.5, you can translate modules depending on the theme. Therefore, the list of translation files is as such:

The translations are stored in a PHP array, named $_MODULE, and take the following form:

The identification key is built by combining the name of the module from which the original string comes (i.e. "blockcms"), following by the name of the theme (i.e. "prestashop"), followed by the name of the file (i.e. "blockmobilecms"), followed by an underscore, and finally the MD5 hash of the string itself.

If one string appears in several different files, it will only appear in the translation tool.

PDF files translations

The following folders are parsed:

The translatable strings use the following syntax:

Two options can be added to these syntaxes:

All the error messages translations are stored in the following file, with iso_code being the ISO 3166-1 code (http://www.iso.org/iso/country_codes.htm) for the language of the translated strings (de, fr, en, it, es, etc.):

If you use the default theme, translations will be stored among the default translations: translations/iso_code/pdf.php

If you use any other theme, translations will be stored in the theme's folder: themes/your_theme/pdf/lang/iso_code.php

The translations are stored in a PHP array, named $_LANGPDF, and take the following form:

The identification key is built by combining "PDF_invoice" (v1.4) or "PDF" (v1.5) with the MD5 hash of the string itself.

If the same string appears in several different controllers, it will appear as many times in the translation tool.

On the other hand, if one string appears in both a controller and its template, it will only appear once for this controller.

E-mail template translations

There are two types of translation when touching upon e-mail templates: the template itself, and the mail object/title. They are completely different things.

Mail objects

The following folders are parsed:

The translatable strings use the following syntax:

Mail::l('Your new admin password', (int)$id_lang)

The second parameter is mandatory. If it is absent, the mail will be sent with an object in the shop's default language.

All the mail translations are stored in the following files, with iso_code being the ISO 3166-1 code (http://www.iso.org/iso/country_codes.htm) for the language of the translated strings (de, fr, en, it, es, etc.):

The translations are stored in a PHP array, named $_LANGMAIL, and take the following form:

The identification key is built by using the original string directly.

Mail templates

The following folders are parsed:

The translated e-mail templates are those available in English. For instance:

Sprintf

The sprint() function, which is standard to PHP, must be used in the correct way throughout PrestaShop.

In PHP files

Correct way:

sprintf($this->l('Empty string found, please edit: "%s"'), $string);
sprintf(Tools::displayError('Please create a "%1$s.php" file in "%2$s"'), $string1, $string2)

Incorrect way:

$this->l('Empty string found, please edit:').'"'.$string.'"';
Tools::displayError('Please create a').' "'.$string1.'.php" '.Tools::displayError('file in').'"'.$string2.'"';

In template files (new in v1.5)

Correct way:

{l s='renamed the /admin folder (e.g. /admin123%d)' sprintf=$number}
{l s='renamed the /%1$s folder (e.g. /admin123%2$d)' sprintf=[$string, $number]}

Incorrect way:

{l s='renamed the /admin folder (e.g. /admin123'}{$number})
{l s='renamed the'} /{$string} {l s='folder (e.g. /admin123'}{$number})