Jump to content

Products names and descriptions in multiple language


redstorm

Was this useful to you?  

34 members have voted

  1. 1. Was this useful to you?



Recommended Posts

Hi, I recently purchased WHMCS and I am happy with it. I recently asked support how to enable multilanguage features for products names and descriptions since they wouldn't change when you change to a different language and they said it was not possible, so I started to play with it and got it working by playing with the templates a bit. This may not be perfect, but so far it seems to work. Also please note I AM NOT A PROGRAMMER, I pretty much copy/pasted codes I found which made sense for what I wanted to do, so any revision anyone can make I would greatly appreciate it:

 

Step 1

Make a duplicate of the order form of your choice you want to test with, this is optional, but I did it so I would keep an original version.  Once duplicated set your ordering form from the admin options to your new folder.  I chose cart for my example.

 

Step 2

Find: products.tpl file within the templates folder and open it with your editor.

 

Step 3

find the line

{foreach key=num item=product from=$products}

This is the loop that process each product found from your database.  Just above it (meaning outside the loop) we will need a PHP function:

{php}
function explode_assoc($glue1, $glue2, $array)
{
 $array2=explode($glue2, $array);
 foreach($array2 as  $val)
 {
           $pos=strpos($val,$glue1);
           $key=substr($val,0,$pos);
           $array3[$key] =substr($val,$pos+1,strlen($val));
 }
 return $array3;
}
{/php}

 

Step 4

Your loop is now just bellow this function, now inside the loop, here is the code we will use:

{php}

// Declare Global Variables
global $num, $products;

// Get Smarty Template Variable Value for current Key in the loop
$num = $this->get_template_vars('num');

// Define current product name from the array
$prdname = $products[$num]['name'];
$prddsc = $products[$num]['description'];

// Explode the array to get language values
$prdnamexpl = explode_assoc('^','||',$prdname);
$prddscxpl = explode_assoc('^','||',$prddsc);

// If array count is 1 or less, then a single language mode is on
if (count($prdnamexpl) <= 1) {
$prdnamexpl = $prdname;
} else {
// Make a new array with the name to be used
$prdnamearr = array('name' => $prdnamexpl[$_SESSION['Language']]);
}

if (count($prddscxpl) <= 1) {
$prddscxpl = $prddsc;
} else {
// Make a new array with the name to be used
$prddscarr = array('description' => $prddscxpl[$_SESSION['Language']]);
}

// Reassign to Smarty Variable (true switch is to merge with existing key)
$this->append('product', $prdnamearr, TRUE);
$this->append('product', $prddscarr, TRUE);
{/php}

 

Basically what I am doing here is using two special set of characters to identify from the product name and description what content belongs to which language.

 

Step 5

You are done editing templates, now go to your product and services section and change a sample product to test, use this syntax:

English^A product Title in English||Spanish^Un titulo de producto en Español

and so on for as many languages you want to add.

 

Please note the || is needed to separate one language from another.

 

Please note, the language name string needs to be exactly the same (case sensitive) as stored in the session created by whmcs.

 

For a product that will be displayed in a unique language you do not need to specify it, just do not use ^ or || anywhere in the content.

 

That's it.

 

It would be awesome if someone with programming experience could take a look at this and maybe make it better, I am sure it can be optimized more, or made a lot simpler.

 

Most importantly, sorry if this was a dumb post, but I was frustrated trying to accomplish this. Like I said, it may not be perfect, but so far, its working for my needs.

 

Cheers!

 

Jose R. Lopez

Link to comment
Share on other sites

I'm curious. What is happen if you miss to specify a language? For example, there are several languages, but just English and Spanish are defined with multi-language, and now the user choose Chinese from WHMCS. What will be displayed? There is a way to specify a 'default' description to be displayed when you miss the specify.

Link to comment
Share on other sites

A very small modification to do what I explain in last post:

 

{php}
// Declare Global Variables
global $num, $products, $CONFIG;

// Get Smarty Template Variable Value for current Key in the loop
$num = $this->get_template_vars('num');

// Define current product name from the array
$prdname = $products[$num]['name'];
$prddsc = $products[$num]['description'];

// Explode the array to get language values
$prdnamexpl = explode_assoc('^','||',$prdname);
$prddscxpl = explode_assoc('^','||',$prddsc);

// If array count is 1 or less, then a single language mode is on
if (count($prdnamexpl) <= 1) {
$prdnamexpl = $prdname;
} else {
// Make a new array with the name to be used
$prdnamearr = array('name' => $prdnamexpl[$CONFIG['Language']]);

if ($prdnamearr['name'] == '') {
	$prdnamearr = array('name' => $prdnamexpl['English']);
}
}

if (count($prddscxpl) <= 1) {
$prddscxpl = $prddsc;
} else {
// Make a new array with the name to be used
$prddscarr = array('description' => $prddscxpl[$CONFIG['Language']]);

if ($prddscarr['description'] == '') {
	$prddscarr = array('description' => $prddscxpl['English']);
}
}

// Reassign to Smarty Variable (true switch is to merge with existing key)
$this->append('product', $prdnamearr, TRUE);
$this->append('product', $prddscarr, TRUE);
{/php}

 

With this, all languages without description will use ENGLISH as default language.

Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...

I have a bug in this script: when you click the order button and there are optional items in the product you have to configure you get a next page. This next page doesn't select on language, but shows you all the content in the description. So in my case, english, dutch and german. This is a bit weird to see, so I couldn't use the script any more.

 

ANybody else having this problem? Can we solve it?

Link to comment
Share on other sites

  • 3 months later...
I have a bug in this script: when you click the order button and there are optional items in the product you have to configure you get a next page. This next page doesn't select on language, but shows you all the content in the description. So in my case, english, dutch and german. This is a bit weird to see, so I couldn't use the script any more.

 

ANybody else having this problem? Can we solve it?

 

 

I have just published an alternative multi-language field MOD that may solve your problem, its really simple, flexible and elegant. See it at

 

http://forum.whmcs.com/showthread.php?p=103963#post103963

Link to comment
Share on other sites

  • 1 year later...
Hi, I recently purchased WHMCS and I am happy with it. I recently asked support how to enable multilanguage features for products names and descriptions since they wouldn't change when you change to a different language and they said it was not possible, so I started to play with it and got it working by playing with the templates a bit. This may not be perfect, but so far it seems to work. Also please note I AM NOT A PROGRAMMER, I pretty much copy/pasted codes I found which made sense for what I wanted to do, so any revision anyone can make I would greatly appreciate it:

 

Step 1

Make a duplicate of the order form of your choice you want to test with, this is optional, but I did it so I would keep an original version.  Once duplicated set your ordering form from the admin options to your new folder.  I chose cart for my example.

Step 2

Find: products.tpl file within the templates folder and open it with your editor.

Step 3

find the line

{foreach key=num item=product from=$products}

This is the loop that process each product found from your database.  Just above it (meaning outside the loop) we will need a PHP function:

{php}
function explode_assoc($glue1, $glue2, $array)
{
 $array2=explode($glue2, $array);
 foreach($array2 as  $val)
 {
           $pos=strpos($val,$glue1);
           $key=substr($val,0,$pos);
           $array3[$key] =substr($val,$pos+1,strlen($val));
 }
 return $array3;
}
{/php}

Step 4

Your loop is now just bellow this function, now inside the loop, here is the code we will use:

{php}

// Declare Global Variables
global $num, $products;

// Get Smarty Template Variable Value for current Key in the loop
$num = $this->get_template_vars('num');

// Define current product name from the array
$prdname = $products[$num]['name'];
$prddsc = $products[$num]['description'];

// Explode the array to get language values
$prdnamexpl = explode_assoc('^','||',$prdname);
$prddscxpl = explode_assoc('^','||',$prddsc);

// If array count is 1 or less, then a single language mode is on
if (count($prdnamexpl) <= 1) {
   $prdnamexpl = $prdname;
} else {
   // Make a new array with the name to be used
   $prdnamearr = array('name' => $prdnamexpl[$_SESSION['Language']]);
}

if (count($prddscxpl) <= 1) {
   $prddscxpl = $prddsc;
} else {
   // Make a new array with the name to be used
   $prddscarr = array('description' => $prddscxpl[$_SESSION['Language']]);
}

// Reassign to Smarty Variable (true switch is to merge with existing key)
$this->append('product', $prdnamearr, TRUE);
$this->append('product', $prddscarr, TRUE);
{/php}

Basically what I am doing here is using two special set of characters to identify from the product name and description what content belongs to which language.

 

Step 5

You are done editing templates, now go to your product and services section and change a sample product to test, use this syntax:

English^A product Title in English||Spanish^Un titulo de producto en Español

and so on for as many languages you want to add.

Please note the || is needed to separate one language from another.

 

Please note, the language name string needs to be exactly the same (case sensitive) as stored in the session created by whmcs.

 

For a product that will be displayed in a unique language you do not need to specify it, just do not use ^ or || anywhere in the content.

 

That's it.

 

It would be awesome if someone with programming experience could take a look at this and maybe make it better, I am sure it can be optimized more, or made a lot simpler.

 

Most importantly, sorry if this was a dumb post, but I was frustrated trying to accomplish this. Like I said, it may not be perfect, but so far, its working for my needs.

 

Cheers!

 

Jose R. Lopez

Sorry , I try to change the product.tpl but nothing to work , can you post the lines when you add it on you .tpl , product.tpl on default orderforms folder or on web20cart or on cart or on boxes ?

Link to comment
Share on other sites

  • 5 months later...

Yepp...

i found a Problem in your Code...

If i go forward next step in Cart.. you can final go with link to configure Domain (step before checkout)

If you there click on configure to edit the package typ, then you get all languages include || ^ Signs..

 

So there must be another Code, what is to edit for multilanguage..

Is there any, what can assist by this one ?

Regards

Kasi

Link to comment
Share on other sites

  • 2 months later...

It is showing both description.

 

It is possible to show acording to the language selected only?

 

 

Hi, I recently purchased WHMCS and I am happy with it. I recently asked support how to enable multilanguage features for products names and descriptions since they wouldn't change when you change to a different language and they said it was not possible, so I started to play with it and got it working by playing with the templates a bit. This may not be perfect, but so far it seems to work. Also please note I AM NOT A PROGRAMMER, I pretty much copy/pasted codes I found which made sense for what I wanted to do, so any revision anyone can make I would greatly appreciate it:

 

Step 1

Make a duplicate of the order form of your choice you want to test with, this is optional, but I did it so I would keep an original version.  Once duplicated set your ordering form from the admin options to your new folder.  I chose cart for my example.

 

Step 2

Find: products.tpl file within the templates folder and open it with your editor.

 

Step 3

find the line

{foreach key=num item=product from=$products}

This is the loop that process each product found from your database.  Just above it (meaning outside the loop) we will need a PHP function:

{php}
function explode_assoc($glue1, $glue2, $array)
{
 $array2=explode($glue2, $array);
 foreach($array2 as  $val)
 {
           $pos=strpos($val,$glue1);
           $key=substr($val,0,$pos);
           $array3[$key] =substr($val,$pos+1,strlen($val));
 }
 return $array3;
}
{/php}

 

Step 4

Your loop is now just bellow this function, now inside the loop, here is the code we will use:

{php}

// Declare Global Variables
global $num, $products;

// Get Smarty Template Variable Value for current Key in the loop
$num = $this->get_template_vars('num');

// Define current product name from the array
$prdname = $products[$num]['name'];
$prddsc = $products[$num]['description'];

// Explode the array to get language values
$prdnamexpl = explode_assoc('^','||',$prdname);
$prddscxpl = explode_assoc('^','||',$prddsc);

// If array count is 1 or less, then a single language mode is on
if (count($prdnamexpl) <= 1) {
$prdnamexpl = $prdname;
} else {
// Make a new array with the name to be used
$prdnamearr = array('name' => $prdnamexpl[$_SESSION['Language']]);
}

if (count($prddscxpl) <= 1) {
$prddscxpl = $prddsc;
} else {
// Make a new array with the name to be used
$prddscarr = array('description' => $prddscxpl[$_SESSION['Language']]);
}

// Reassign to Smarty Variable (true switch is to merge with existing key)
$this->append('product', $prdnamearr, TRUE);
$this->append('product', $prddscarr, TRUE);
{/php}

 

Basically what I am doing here is using two special set of characters to identify from the product name and description what content belongs to which language.

 

Step 5

You are done editing templates, now go to your product and services section and change a sample product to test, use this syntax:

English^A product Title in English||Spanish^Un titulo de producto en Español

and so on for as many languages you want to add.

 

Please note the || is needed to separate one language from another.

 

Please note, the language name string needs to be exactly the same (case sensitive) as stored in the session created by whmcs.

 

For a product that will be displayed in a unique language you do not need to specify it, just do not use ^ or || anywhere in the content.

 

That's it.

 

It would be awesome if someone with programming experience could take a look at this and maybe make it better, I am sure it can be optimized more, or made a lot simpler.

 

Most importantly, sorry if this was a dumb post, but I was frustrated trying to accomplish this. Like I said, it may not be perfect, but so far, its working for my needs.

 

Cheers!

 

Jose R. Lopez

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