Jump to content

Multilanguage product description: a simple approach


nasos75

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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' )

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  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.

Link to comment
Share on other sites

  • 1 year later...

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated