nasos75 Posted December 10, 2012 Share Posted December 10, 2012 There are already some other approaches, but I think this one request less customization. The following example is for greek and english languages: 1. Open your products.tpl template. 2. Find the line with: <tr><td width="40%"><strong>{$product.name}</strong>. 3. Between <tr> and <td> insert the following code: {php} $myvar=$this->get_template_vars('product'); $pname=$myvar['name']; // *********** Optional code starts here *********** if( strpos($pname,'<greek>') !== FALSE && strpos($pname,'<english>') !== FALSE ) { if( $this->get_template_vars('language') == 'greek' ) { $pname=substr($pname,strpos($pname,'<greek>')+13); $pname=substr($pname,0,strpos($pname,'</greek>')); } else { $pname=substr($pname,strpos($pname,'<english>')+15); $pname=substr($pname,0,strpos($pname,'</english>')); } } // *********** Optional code ends here *********** $this->assign('multilangproductname',$pname); if( isset($myvar['description']) ) { $descr=$myvar['description']; if( strpos($descr,'<greek>') !== FALSE && strpos($descr,'<english>') !== FALSE ) { if( $this->get_template_vars('language') == 'greek' ) { $descr=substr($descr,strpos($descr,'<greek>')+7); $descr=substr($descr,0,strpos($descr,'</greek>')); } else { $descr=substr($descr,strpos($descr,'<english>')+9); $descr=substr($descr,0,strpos($descr,'</english>')); } } $this->assign('multilangproductdescr',$descr); } {/php} 4. Change then <tr><td width="40%"><strong>{$product.name}</strong> to <tr><td width="40%"><strong>{$multilangproductname}</strong> 5. Change next line from {if $product.description}{$product.description}<br /> to {if $product.description}{$multilangproductdescr}<br /> In the product description write your description as: <greek>This is the greek description</greek><english>This is the english description</english>. The result is obvious I guess. If no <greek> AND no <english> tags are found, the raw description will be displayed. The same goes with product name, so why the optional code? WHMCS uses product name in many places, not just in products.tpl (email templates for example). So you will need to modify more templates if you also need a multilingual product name, not just products.tpl. In other words, use the $multilangproductdescr and $mlutilangproductname variables in place of the default $product.description and $product.name. Change the ifs in the above code according to your language needs, and/or replace else with if for more than two languages. I hope you'll find this little tweak helpful. Nasos 0 Quote Link to comment Share on other sites More sharing options...
keneso Posted December 13, 2012 Share Posted December 13, 2012 That's only in web20cart. Do you have it for modern, or comparison as well? Thank you 0 Quote Link to comment Share on other sites More sharing options...
nasos75 Posted December 14, 2012 Author Share Posted December 14, 2012 This is for web20cart but the concept is the same for other templates. In modern for example, look for $product.featuresdesc instead of $product.description and in the code above convert language variable to lower case ($this->get_template_vars('language') to strtolower($this->get_template_vars('language'))). The code must be placed before <div class="name">. Let me know if you would like to ask something else. 0 Quote Link to comment Share on other sites More sharing options...
imaticon Posted December 14, 2012 Share Posted December 14, 2012 Hi Nasos, Really nice solution! Thank you for your free contribution. Regards, Marco 0 Quote Link to comment Share on other sites More sharing options...
keneso Posted December 14, 2012 Share Posted December 14, 2012 Thank you. I know I must have messed somewhere due to my lack of php knowledge, I get a blank page. Following is the code I put (trying) following your suggestion {php} $myvar=$this->get_template_vars('product'); $pname=$myvar['name']; // *********** Optional code starts here *********** if( strpos($pname,'<italian>') !== FALSE && strpos($pname,'<english>') !== FALSE ) { if strtolower(($this->get_template_vars('language')) == 'italian' ) { $pname=substr($pname,strpos($pname,'<italian>')+13); $pname=substr($pname,0,strpos($pname,'</italian>')); } else { $pname=substr($pname,strpos($pname,'<english>')+15); $pname=substr($pname,0,strpos($pname,'</english>')); } } // *********** Optional code ends here *********** $this->assign('multilangproductname',$pname); if( isset($myvar['description']) ) { $descr=$myvar['description']; if( strpos($descr,'<italian>') !== FALSE && strpos($descr,'<english>') !== FALSE ) { if strtolower(($this->get_template_vars('language')) == 'italian' ) { $descr=substr($descr,strpos($descr,'<italian>')+7); $descr=substr($descr,0,strpos($descr,'</italian>')); } else { $descr=substr($descr,strpos($descr,'<english>')+9); $descr=substr($descr,0,strpos($descr,'</english>')); } } $this->assign('multilangproductdescr',$descr); } {/php} <div class="description">{$product.featuresdesc}</div> My doubt is about the strtolower(($this->get_template_vars('language')) == 'italian' ) and number of parentheses. I tried all these strtolower($this->get_template_vars('language') == 'italian' ) strtolower($this->get_template_vars('language')) == 'italian' ) strtolower(($this->get_template_vars('language')) == 'italian' ) 0 Quote Link to comment Share on other sites More sharing options...
imaticon Posted December 14, 2012 Share Posted December 14, 2012 Hi, You need to pass the correct length value for italian: $descr=substr($descr,strpos($descr,'<italian>')+9); $pname=substr($pname,strpos($pname,'<italian>')+15); Regards, Marco 0 Quote Link to comment Share on other sites More sharing options...
keneso Posted December 14, 2012 Share Posted December 14, 2012 Thank you. I did change the lenght values, but still get the blank page. Might it have to do with the default language selected in admin? Just to be sure, will you please tell me which parentheses numebr to use on my previous post, I tried themn all, and get the blank page. Regards 0 Quote Link to comment Share on other sites More sharing options...
nasos75 Posted December 14, 2012 Author Share Posted December 14, 2012 The correct syntax is: if( strtolower($this->get_template_vars('language')) == 'italian' ) You forgot the parenthesis after if, this is why you get a blank page (it is a php syntax error). As imaticon said (thank you), you should change the length 13/15/7/9 depending the length of the name of the languages you want. 0 Quote Link to comment Share on other sites More sharing options...
imaticon Posted December 14, 2012 Share Posted December 14, 2012 The provided code from nasos works correctly. I guess you have in your products.tpl file some other errors. I suggest to copy/paste the original code from nasos and then simple replace for italian the correct length value as provided above. Additionally activate display_error in whmcs settings to see the php error. Regards, Marco 0 Quote Link to comment Share on other sites More sharing options...
keneso Posted December 14, 2012 Share Posted December 14, 2012 nasos75 said: The correct syntax is: if( strtolower($this->get_template_vars('language')) == 'italian' ) You forgot the parenthesis after if, this is why you get a blank page (it is a php syntax error). As imaticon said (thank you), you should change the length 13/15/7/9 depending the length of the name of the languages you want. Great. Thank you very much for the patience. I knew it was the parentheses ... I had already fixed the lenght as by imaticon's suggestion. It all works now. 0 Quote Link to comment Share on other sites More sharing options...
int Posted May 24, 2014 Share Posted May 24, 2014 Great solution to the lack of multilanguage support in product/group descriptions. However, after implementing this solution, the email templates don't display the product or group names correctly (everything shows with <english> and whatever other language you've implemented). Is there a simple solution for emails? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.