Jump to content

MOD : Multilingual Products (in fact any value you want)


Did you find this mod useful?  

87 members have voted

  1. 1. Did you find this mod useful?

    • Yes
      83
    • No
      4


Recommended Posts

Hey Man grate mod , thx for sharing with the crowd

 

i am getting some trouble with applying it

 

getting this on the output

 

English contentFrench content , even when i am switching the langs

 

 

i have done all steps

 

1. added code to function.getlang.php file and uploaded to libs/plugins

2. added {getlang data=$product.name lang=$language} and description to products.tpl file in order form

3. added <English>English content</English><French>French content</French> via admin to my product description

 

no luck

 

please advise

 

 

Kind Regards

Link to comment
Share on other sites

  • Replies 85
  • Created
  • Last Reply

Top Posters In This Topic

  • 5 weeks later...
$data = str_replace("[##","<",$data);

$data = str_replace("[#","]]></",$data);

$data = str_replace("<p>[##","<",$data);

$data = str_replace("<p>[#","]]></",$data);

$data = str_replace("##]",">",$data);

$data = str_replace("##]</p>",">",$data);

$data = str_replace("#]","><![CDATA[",$data);

$data = str_replace("#]</p>","><![CDATA[",$data);

$data = str_replace("##][##","><",$data);

 

fix for non wywiwyg strings. You forgot the regular [##, [#, #] and ##] tags...

 

This code is not correct ! But the following will works ! (You first have to check with <p> tags before ;-)

 

    $data = str_replace("<p>[##","<",$data);
   $data = str_replace("<p>[#","]]></",$data);
   $data = str_replace("[##","<",$data);
   $data = str_replace("[#","]]></",$data);
   $data = str_replace("##]</p>",">",$data);
   $data = str_replace("##]",">",$data);
   $data = str_replace("#]</p>","><![CDATA[",$data);
   $data = str_replace("#]","><![CDATA[",$data);
   $data = str_replace("##][##","><",$data);

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 months later...

Thanks for great mod :)

 

But to use all characters you should change xml coding to UTF-8. Otherwise it will display some characters incorrectly.

$xmldata ='<?xml version="1.0" encoding="ISO-8859-1" ?><root>'.$params['data'].'</root>';

to

$xmldata ='<?xml version="1.0" encoding="UTF-8" ?><root>'.$params['data'].'</root>';
Link to comment
Share on other sites

  • 2 weeks later...

Hi,

 

Thank you for your great contribution. I've followed all the steps carefully. However, I got the following output:

 

Product Description

English content Chinese content ...

 

Group Name

<English>English content></English><Chinese>Chinese content</Chinese>...

 

http://www.sinoland.com/whmcs/cart.php?language=English

 

The database value of product groups name is

 

<English>Industry Web Hosting</English>

 

 

Please help. Thank you.

Edited by sino
Link to comment
Share on other sites

Hi,

 

My database is utf8_unicode_ci. When I change all '<' to '<' and '>' to '>' via phpMyAdmin. It works. So how can I correct this issue? That is, '<' and '>' entered into admin. would be saved as '<' and '>' in the database respectively.

 

I'm not good at those encoding and database. Please help. Thank you in advance.

Link to comment
Share on other sites

Hi guys,

 

great plugin but im not being able to get it working....it showing the language tags and all the info like:

 

<English>This is English</English><Italian>Questo è l'italiano</Italian> in the product group

 

im using v 4.1.2 of whmcs

 

any idea?

 

Should i have to reload something after create the plugin file in the smarty plugin directory?

 

Thanx in advance!

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...
Hi,

nice solution but it just does not work in the view cart product configuration page. I still get the <English>group name</English><French.> etc.. tags. Any idea how to fix this? I would really appreciate

Thanks

Hi,

 

I encounter the same issue and discover that I forget to update the variable, say $groupname to

{getlang data=$groupname lang=$language} in clientareaproductdetails.tpl.

 

Have to update all variables in concern.

 

Possible variables/files to update:

{$product.productinfo.groupname}

{$product.productinfo.name}

viewcart.tpl (Web20cart)

 

Hope this helps.

 

Regards,

Sino

Link to comment
Share on other sites

  • 5 weeks later...
Here is an updated script and some instructions for allowing multi-language content in WYSIWYG editor fields.

 

Please note this is somewhat of a hack and you need to be careful exactly how you structure the page to make sure no stray html code gets trapped between tags (p tags surrounding the tags are okay and in fact have to be there for the sudo tag conversion to work )

 

In the WYSIWYG editor you can place the sudo codes surrounding your content like so

 

[##English#]

This is english

[#English##]

[##Italian#]

This is Italian

[#Italian##]

 

The html should come out something like this

 

<p>[##English#]</p>
<p>This is english</p>
<p>[#English##]</p>
<p>[##Italian#]</p>
<p>This is Italian</p>
<p>[#Italian##]</p>

 

Please make sure that no additional p tags (Apart from the ones above which are catered for) fall outside of the surrounding tags or likely the conversion will not work and the whole string will be outputted instead.

 

The modified script to is below, enjoy

 


<?php
/*
* Smarty plugin
* ————————————————————-
* File:     function.getlang.php
* Type:     function
* Name:     XML Language Data
* Purpose:  Returns only the language data surrounded by language tags
* ————————————————————-
*/
function smarty_function_getlang($params, &$smarty){

// Set a default language
$deflang ="English";

// Convert sudocode from wysiwyg editor
$data = str_replace("<p>[##","<",$params['data']);
$data = str_replace("<p>[#","]]></",$data);
$data = str_replace("##]</p>",">",$data);
$data = str_replace("#]</p>","><![CDATA[",$data);
$data = str_replace("##][##","><",$data);

// process data
$xmldata ='<?xml version="1.0" encoding="ISO-8859-1" ?><root>'.$data.'</root>';
$lang = $params['lang'];
if(simplexml_load_string($xmldata)===FALSE) {
	return $params['data'];
} else {
	$langxmlobj = new SimpleXMLElement($xmldata);
	if ($langxmlobj->$lang){
		return $langxmlobj->$lang;
	} elseif ($langxmlobj->$deflang){
		return $langxmlobj->$deflang;
	} else {
		return $params['data'];
	}
}
}
?>

 

I noticed that WHMCS is lacking in the ability to add product titles and descriptions in multiple languages and although there is a mod solution already published http://forum.whmcs.com/showthread.php?t=15045&highlight=products+multiple+languages it is not the most elegant or flexible solution so I decided to create something better.

 

This solution uses Smarties own plug-in functionality to allows you to easily add multilingual content to any field in the admin. It works by surrounding the content in simple xml tags e.g.

 

<English>English content</English>

<French>French content</French>

 

First thing you need to do is create a plug-in file in the following folder

 

/whmcs/includes/smarty/plugins/function.getlang.php

 

and add the following code to the file

 


<?php
/*
* Smarty plugin
* ————————————————————-
* File:     function.getlang.php
* Type:     function
* Name:     XML Language Data
* Purpose:  Returns only the language data surrounded by language tags
* ————————————————————-
*/
function smarty_function_getlang($params, &$smarty){
$xmldata ='<?xml version="1.0" encoding="ISO-8859-1" ?><root>'.$params['data'].'</root>';
$lang = $params['lang'];
if(simplexml_load_string($xmldata)===FALSE) {
	return $params['data'];
} else {
	$langxmlobj = new SimpleXMLElement($xmldata);
	if ($langxmlobj->$lang){
		return $langxmlobj->$lang;
	} else {
		return $params['data'];
	}
}
}
?>


 

Next for any smarty variable that outputs data entered into the admin E.g. the $product.name or $product.description tag in your orderforms you can replace it with the tag below (Note the script will output the full value if no tags are found)

 


{getlang data=$product.name lang=$language}

 

OR

 


{getlang data=$product.description lang=$language}

 

It is then just a simple job or adding the content in the admin with the correct names based on your sites language.

 

<English>English content</English><French>French content</French

 

If anyone finds any bugs then please post them here

 

 

Hi

 

where i put this code : {getlang data=$product.description lang=$language}

Link to comment
Share on other sites

First of all, thanks for this piece of code, it´s really works like charm!

 

But now I found an issue: I want to include html code in product description, and I´m not being able of do it. Let´s put an example:

 

<English>

This is plain text

<p>This is a paragraph</p>

</English>

 

results on:

 

This is plain text

 

 

Seems like the html code gets removed, and I cant find the solution for that. Can you please help me with that? Thank you!

Link to comment
Share on other sites

Update:

 

Shame on me, it´s obvious that is not gonna work with html tags on textarea, it´s being taken as a xml tag by the parser. I changed a bit the code for doing the trick, gonna share it now:

 

<?php
/*
* Smarty plugin
* ————————————————————-
* File:     function.getlang.php
* Type:     function
* Name:     XML Language Data
* Purpose:  Returns only the language data surrounded by language tags
* ————————————————————-
*/
function smarty_function_getlang($params, &$smarty){

   // Default language
$deflang ="English";

if(isset($params['lang']))
	$lang = $params['lang'];
   else
	$lang = $deflang;

   $data = $params['data']; 
$data = str_replace("<","**",$data);
$data = str_replace(">","*",$data);
$data = str_replace("**" . $lang . "*", "<" . $lang . ">",$data);
$data = str_replace("**/" . $lang . "*", "</" . $lang . ">",$data); 

   // process data
   $xmldata ='<?xml version="1.0" encoding="ISO-8859-1" ?><root>'.$data.'</root>';
   if(simplexml_load_string($xmldata)===FALSE) {
       return $params['data'];
   } else {
       $langxmlobj = new SimpleXMLElement($xmldata);
       if ($langxmlobj->$lang){
       	$data = str_replace("**","<",$langxmlobj->$lang);
		$data = str_replace("*",">",$data); 
           return $data;
       } else {
           return $params['data'];
       }
   }
}
?>

 

Please have in mind that this will only work in cases line mine, where you want to add html tags to fields like Product Description.

 

Hope it helps someone!

Link to comment
Share on other sites

First of all, thanks for this piece of code, it´s really works like charm!

 

But now I found an issue: I want to include html code in product description, and I´m not being able of do it. Let´s put an example:

 

<English>

This is plain text

<p>This is a paragraph</p>

</English>

 

results on:

 

This is plain text

 

 

Seems like the html code gets removed, and I cant find the solution for that. Can you please help me with that? Thank you!

 

You need to wrap html in <![CDATA

]> tags

 

e.g.

 

<English><![CDATA[

html content

]]></English>

Link to comment
Share on other sites

  • 1 month later...

Hello,

everybody I'm new on this forum and new user of WHMCS. I've tried to install the language function on my WHMCS but I must be too dumb. I don't hunderstand what I should really.

 

I'm french (living in france) so I apologize for my english.

 

If someone have time to give me a hand, it will be nice.

Thanks in advance

Mohamed

Link to comment
Share on other sites

  • 1 month later...

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