Translations in PrestaShop modules: domains, catalogues and common mistakes
If your module shows up in English in a Spanish store, it is almost always a misspelt domain or a cache. We explain how the PrestaShop translation system works.
PrestaShop has two translation systems living side by side: the old one ($this->l() and PHP files in translations/) and the new one, based on Symfony domains. For a new module, use the new one.
Enabling the new system
public function isUsingNewTranslationSystem()
{
return true;
}
Domains
Each string belongs to a domain of the form Modules.Nombremodulo.Zona, where the module name has its first letter in upper case and the rest in lower case:
Modules.Mimodulo.Adminfor the back office.Modules.Mimodulo.Shopfor the front office.
// PHP
$this->trans('Order shipped', [], 'Modules.Mimodulo.Shop');
{* Smarty *}
{l s='Order shipped' d='Modules.Mimodulo.Shop'}
{# Twig #}
{{ 'Order shipped'|trans({}, 'Modules.Mimodulo.Admin') }}
Why a translation does not appear
- Misspelt domain.
Modules.MiModulo.Shopis not the same asModules.Mimodulo.Shop. - The source text changed. The translation is looked up by the exact text; one space or comma of difference and it no longer matches.
- Cache. Translations are cached; after importing them, clear the cache.
- The theme has its own copy of the template. If the theme overrides the module template, the translation is looked up in association with that theme. Save the translation for the active theme as well.
Parameters and plurals
$this->trans('You have %count% products', ['%count%' => $n], 'Modules.Mimodulo.Shop');
Use named placeholders and never concatenate sentences: word order changes from one language to another.
Distributing translations
Export the catalogues from International > Translations and include them in the module ZIP, so that on a new store it appears translated from the very first moment. And always check the module with the store in at least two languages before publishing.