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

  • 1 month later...
  • Replies 85
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 months later...

Hi Guys,

 

I'm using ServWise module. <english>Text here</english><spanish>Texto aquí</spanish> and work very well and no problem with it.

 

Now, how I can change or make this work on emails and invoices? Also, the admin console, in the products and services, look like a scramble place. How I can get this to work as well?

 

Thanks in advance,

Link to comment
Share on other sites

  • 7 months later...

The solution posted for me didn't provide images.

 

So I wrote my own.

 

Mine is simple, I simply just return all the data between two values

 

function smarty_function_getlang($params, &$smarty){

 

require_once 'outside_file.php';

 

foreach($params as $key => $value)

{

$$key = $value;

}

 

return OUTSIDE_FUNCTION::substr_delimeters($data, '<' . $lang . '>', '</' . $lang . '>');

 

}

 

static function substr_delimeters($inputstr,$delimeterLeft,$delimeterRight) {

if (empty($inputstr) || empty($delimeterLeft) || empty($delimeterRight)) return false;

$posLeft = stripos($inputstr,$delimeterLeft)+strlen($delimeterLeft);

$posRight = stripos($inputstr,$delimeterRight,$posLeft+1);

if (($posLeft===false) || ($posRight===false)) return false;

return substr($inputstr,$posLeft,$posRight-$posLeft);

}

Link to comment
Share on other sites

  • 7 months later...

Hi. I'm trying to use the plugin and It's working quite fine, but I have an issue:

 

It works properly with the description of the packages but not with the name. I used the option {debug} to see ve values from the variables and I discovered something strange:

 

name => "<english>Wordpress will be inst..."

description => "<english>Wordpress will be installed ..."

 

I think this is the reason why is not working with the names: the function SimpleXMLElement($xmldata); is not recognizing the text as XML because there is no < >. any idea how to solve that? I think It could be done if there is any php function that allows to change a character o character string inside the variable, but i don't know if there is something like That.

Link to comment
Share on other sites

Solved. If there is somebody with the same problem (now or in the future) this is my solution. adding to lines in the code:

 

$xmldata=str_replace('<','<',$xmldata);

$xmldata=str_replace('>','>',$xmldata);

 

after

 

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

Link to comment
Share on other sites

  • 7 months later...

Hi, thanks for this plugin, it works great! I just have a question... For configurable products I add on my configureproduct.tpl the code {getlang data=$options.name lang=$language} and the Option name shows in the selected language but the price disappears .

 

Any way to make this work?

 

Thanks!

 

Ernesto

Link to comment
Share on other sites

  • 8 months later...

I made (hopefully) an improvement.

 

Using this function (instead of the original one) you take away from a string (title, description, payment gateway name, whatever) the text enclosed in html tags

 

so even if I have a string like (for example in the sidebar of Version six, or in some other cases):

Addons (ogbuhOBUH.gvyibuhonij.it) - <italian>IP dedicato (mensile)</italian><english>Dedicated IP (Monthly)</english> (01/10/2015 - 31/10/2015)

it takes away every thing enclosed in HTML tags but the text enclosed in you target language tags.

If you want to keep certain html tags just add them in the $tags variable, so that they will not be deleted

 

This way we can translate the invoices. Also, the code you have to add in your template is the same so you only have top modify your function

 

<?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){ 

$deflang = "english";
   $lang = $params['lang'];
   $text = $params['data'];

   if (strpos($text, $lang) == false) {
   	$lang = $deflang;
}

   $text=str_replace('<','<',$text);
$text=str_replace('>','>',$text);
   $tags = "<$lang>,<strong>,<br>";

  preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags); 
  $tags = array_unique($tags[1]); 

  if(is_array($tags) AND count($tags) > 0) { 
	if($invert == FALSE) { 
	  return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text); 
	} 
	else { 
	  return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text); 
	} 
  } 
  elseif($invert == FALSE) { 
	return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text); 
  } 
  return $text; 


} 

?>

 

- - - Updated - - -

 

I'm still trying to figure out how to add this in the pdf invoice tough

Link to comment
Share on other sites

to solve with the pdf invoices I came out with the following solution.

I changed this code:

foreach ($invoiceitems as $item) {
   $tblhtml .= '
   <tr bgcolor="#fff">
       <td align="left">' . nl2br($item['description']) . '<br /></td>
       <td align="center">' . $item['amount'] . '</td>
   </tr>';
}

with:

foreach ($invoiceitems as $item) {

$text = $item['description'];
$lang = Lang::trans('language_name');
$text=str_replace('<','<',$text);
$text=str_replace('>','>',$text);
$tags = "<$lang>,<strong>,<br>,<input>,<select>,<option>";

  preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags); 
  $tags = array_unique($tags[1]); 

  if(is_array($tags) AND count($tags) > 0) { 
	  $text = preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
  } 
  else { 
		  $text = preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text); 
  } 

   $tblhtml .= '
   <tr bgcolor="#fff">
       <td align="left">' . nl2br($text) . '<br /></td>
       <td align="center">' . $item['amount'] . '</td>
   </tr>';
}

 

I had to create a language variable "language_name":

$_LANG["language_name"] = "english";

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