Pass a variable inside translation string in Prestashop

prestashop translation module
prestashop configuration::get
prestashop 1.6 hooks
module translation

I need to pass a variable with a translation string in Prestashop. In the Backend It is possible to do like

sprintf($this->l('The number is %1$d'), $number);

But I need to do this in the front-end while using SMARTY ? is anyone there to help me ?


something like this :

{l s='The number is %1$d' sprintf=$number}

smarty, I need to pass a variable with a translation string in Prestashop. In the Backend It is possible to do like sprintf($this->l('The number is %1$d'), $number);. 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.


1 - On PrestShop v1.7.4 with @skiplecariboo answer {l s='The number is %1$d' sprintf=$number} I'm getting:

Catchable Fatal Error: Argument 2 passed to PrestaShopBundle\Translation\TranslatorComponent::trans() must be of the type array, string given, called in /vagrant/httpdocs/config/smartyfront.config.inc.php on line 210 and defined

2 - With official 3rd party module translation method {l s='The number is %1$d' sprintf=$number mod='my_module'}, I'm getting the same error:

Catchable Fatal Error: Argument 2 passed to PrestaShopBundle\Translation\TranslatorComponent::trans() must be of the type array, string given, called in /vagrant/httpdocs/config/smartyfront.config.inc.php on line 210 and defined

3 - And with official native module translation method {l s='The number is %1$d' sprintf=$number d='Modules.my_module'}, I'm getting:

Unable to translate "The number is %1$d" in module:my_module/my_module.tpl. sprintf() parameter should be an array.

So, solution for me was to set $number variable as an array:

{l s='The number is %1$d' sprintf=[$number] mod='my_module'}

NB: %1$d flag is for decimal, for a string, use: %1$s (source)

Pass a variable inside translation string in Prestashop, I need to pass a variable with a translation string in Prestashop. In the Backend It is possible to do like sprintf($this->l('The number is %1$d'), $number); But I  Pass a variable inside translation string in Prestashop. I need to pass a variable with a translation string in Prestashop. can passe a variable in the


this is how you can passe a variable in the translated string

{l s='Comment: # %id%' mod='ayalinecomments' sprintf=['%id%' => $comment.id_ayalinecomments_comment]}

prestashop will replace %id% by my variable $comment.id_ayalinecomments_comment

ty

Classic translation system :: PrestaShop Developer Documentation, Hi In my module, I have an AdminController inside which I would like to write some texts if it's fr.php, de.php or something, simply check if you have valid string there. Via this code you access the $_LANG gloabl variable (and not the You should not pass controller class name, just use controller name. Klemart3D. Apparently, this user prefers to keep an air of mystery about them. prestashop-1.6. Score 1. 2 Pass a variable inside translation string in


Translation in module Controller ? - Addons, modules , Sometimes, we need to create a global function that have some strings and we must translate these strings. Basically for making our strings  New module translation system The new module translation system is based on the new system introduced in PrestaShop 1.7 for the Core and Native modules. It aims to harmonize translation systems throughout PrestaShop while providing backwards compatibility.


How to make a string translatable in any Class of Prestashop, This way, strings can be directly translated inside PrestaShop: Passing variables to these methods will prevent those wordings from appearing in the  The translation tool needs it in order to match the string to translate with its translation. This parameter is mandatory for module translation. Strings are delimited with single quotes. If a string contains single quotes, they should be escaped using a backslash (\). This way, strings can be directly translated inside PrestaShop:


Improve documentation on module translation · Issue #321 , I tried to pass many different domains like these ones: Shop.Theme.Global This is critical any new strings in . It's very important and critical because I can't send translated variables to my javascript files with this issue. Always use literal values, not variables, with the trans() function, the {l} Smarty tag, and trans Twig filter. Although variables are interpolated at runtime, they won’t be understood by the code analyzer, which only supports literals. Passing variables as arguments to these functions will prevent those wordings from being added to the catalogue.