stratboy Posted May 19, 2015 Share Posted May 19, 2015 Hi, I need to do something like this: {l s="se stai inserendo un indirizzo per consegna all'interno dell'area <span class=orange>EXPO</span>"} Doesn't work. I also tried to use sprintf like this, but still doesn't work: {l s="se stai inserendo un indirizzo per consegna all'interno dell'area %s"|sprintf:'<span class="orange">EXPO</span>'} How to solve? I need this because the EXPO word will vary its position in translations. Link to comment Share on other sites More sharing options...
Tung at RockPOS.com Posted May 26, 2015 Share Posted May 26, 2015 Hello, Let me explain why it does not work for you. 1. You can not put html into {l s=''} as this plugin/ function does not understand html tags; it only accepts text / string. 2. You can not use "printf" too, as {l s =''} is a custom function / plugin added by PrestaShop. I mean, it's not a Smarty function. And this function only accepts 2 params: "s" = string and "mod" = module. And here are the solutions, actually, they are the same, but one works at your PHP code, and one work at Smarty template. Any of them works for you for sure. The main idea is to use PHP function str_replace or Smarty function replace: 1. Use PHP str_replace: http://php.net/str_replace // controller or module class $my_translations = array(); $my_translations['my_trans_welcome_to'] = str_replace( array('[span]', '[/span]'), array('<span class="orange">', '</span>'), $this->l('Welcome to [span]EXPO[/span]!') ); $this->context->smarty->assign($my_translations); //in Smarty template: {$my_trans_welcome_to} 2. Use Smarty function: http://www.smarty.net/docsv2/en/language.modifier.replace.tpl // controller or module class $this->context->smarty->assign(array( 'my_translation_welcome' => $this->l('Welcome to [span]EXPO[/span]') ) ); //in Smarty template: {$my_translation_welcome|replace:'[span]':'<span style="color:red">'|replace:'[/span]':'</span>'} Hope that helps! Link to comment Share on other sites More sharing options...
stratboy Posted May 26, 2015 Author Share Posted May 26, 2015 Thank you they are both viable solutions, but I don't want to modify core controllers, nor I want to override them only to translate a sentence.My solution, in the end, was this: {capture "string1"}{l s="if your delivery address is in the _ospan_EXPO_cspan_ area"}{/capture} <span class="orange">{l s="ATTENTION"}:</span> {$smarty.capture.string1|replace:'_ospan_':'<span class="orange">'|replace:'_cspan_':'</span>'} {l s="remember to"} <span class="orange">{l s="FILL THE TWO FIELDS BELOW"}</span> {l s="otherwise we will not be able to process your order correctly"}. Basically, capture 'saves' the string without writing it. So I can use placeholders for tags (they'll be seen even on the BO translation page) and later replace them with the relavant code.Regards Link to comment Share on other sites More sharing options...
Tung at RockPOS.com Posted May 27, 2015 Share Posted May 27, 2015 Yes, that's a good one too. Anyway, my suggestion is to NOT break 1 sentence into many blocks {l s=''}. You know, the word order is different from language to language. Link to comment Share on other sites More sharing options...
stratboy Posted May 27, 2015 Author Share Posted May 27, 2015 I broken it only when I could, otherwise one can just use the placeholders everywhere. Link to comment Share on other sites More sharing options...
Tung at RockPOS.com Posted May 27, 2015 Share Posted May 27, 2015 Ok cool. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now