July 29, 2010, 10:54:38 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to JROX.COM Forums! 
 
Pages: [1]
  Print  
Author Topic: Easy translations for products  (Read 337 times)
intercel
Newbie
*
Offline Offline

Posts: 39


View Profile
« on: March 10, 2010, 12:48:49 AM »

It took a while, but, I was finally able to come up with a pretty simple translation tool.  It takes a little coding, but it shouldn't be too bad.  Hope this helps someone.

This tutorial will take you through creating a "translation" tool for the product details page.  Use the same code in other parts of the products controller to expand beyond the product details page.

1.) Open yourRootDomain/system/application/controllers/products.php in your favorite editor.  Around line 594 or just after you see this code in the details function:
Code:
//merge the product data
foreach ($sdata['info'] as $k => $v)
{
  $data[$k] = $v;
}
put this code in
Code:
if ($this->session->userdata('user_language_set')=='english' || $this->session->userdata('user_language_set')==''){
// set things up for default language replacements by clearing out other languages in the description area$data['product_overview'] = preg_replace("/{spanish}.*/", "", $data['product_overview']);
}

if ($this->session->userdata('user_language_set')=='spanish'){
// set things up for spanish language replacements by clearing out other languages in the description area
$data['product_overview'] = preg_replace("/.*{spanish}/", "", $data['product_overview']);
$data['product_overview'] = preg_replace("/{\/spanish}.*/", "", $data['product_overview']);
$data['product_description_1'] = preg_replace("/.*{spanish}/", "", $data['product_description_1']);
$data['product_description_1'] = preg_replace("/{\/spanish}.*/", "", $data['product_description_1']);
$data['product_description_2'] = preg_replace("/.*{spanish}/", "", $data['product_description_2']);
$data['product_description_2'] = preg_replace("/{\/spanish}.*/", "", $data['product_description_2']);
}

2.) Go to your JEM admin back office and edit a product overview, description, and features. for the new spanish translation just type in {spanish}Espanol goes here{/spanish}

3.) You're done, unless you want to add aditional languages, in which case you add another line in the English IF statement (copy the spanish line and replace "spanish" with the new language). Copy the whole Spanish IF statement and replace "spanish" with the new language name.
Logged
jroxadmin
JROX Admin
Administrator
Advanced Member
*****
Offline Offline

Posts: 7572


View Profile WWW Email
« Reply #1 on: March 11, 2010, 05:33:41 AM »

very nice!
Logged

Want a Completely Integrated eCommerce System?
JEM = Shopping Cart, Affiliate Marketing, Content Manager, Help Desk, All-In-One!
www.jrox.com
intercel
Newbie
*
Offline Offline

Posts: 39


View Profile
« Reply #2 on: March 12, 2010, 04:23:11 AM »

Hello all,

I redid the code for the translations.  This time it's more dynamic, so you don't have to go back and add more code when you want a different language.  You will have to make all your default english version go between [english][/english] (changed from {} because the home store page didn't like them) tags though.

You'll be adding this code just under the foreach statement listed in the method above in the following functions (search, category, new_products, manufacturer, details) in the /controllers/products.php
Code:
//setup for translations
// get the language selected, if not selected set to default
$langSelected = $this->session->userdata('user_language_set');
if ($langSelected =='') {
$langSelected = 'english';  //set this to whatever language you want to default to.
}
$transBeginTag = '/.*\['. $langSelected . '\]/';
$transEndTag = '/\[\/'.$langSelected.'\].*/';
// set things up for default language replacements by clearing out other languages in the description area
$data['product_overview'] = preg_replace($transBeginTag, "", $data['product_overview']);
$data['product_overview'] = preg_replace($transEndTag, "", $data['product_overview']);
$data['product_description_1'] = preg_replace($transBeginTag, "", $data['product_description_1']);
$data['product_description_1'] = preg_replace($transEndTag, "", $data['product_description_1']);
$data['product_description_2'] = preg_replace($transBeginTag, "", $data['product_description_2']);
$data['product_description_2'] = preg_replace($transEndTag, "", $data['product_description_2']);

Secondly, for the homepage or store page (which was a real pain to figure out), you'll need to modify /models/products_model.php (can't seem to do it at the controller level, oh well) about line 1124, add the following code:
Code:
//setup for translations
// get the language selected, if not selected set to default
$langSelected = $this->session->userdata('user_language_set');
if ($langSelected =='') {
$langSelected = 'english';  //set this to whatever language you want to default to.
}
$transBeginTag = '/.*\['. $langSelected . '\]/';
$transEndTag = '/\[\/'.$langSelected.'\].*/';
// set things up for default language replacements by clearing out other languages in the description area
$row['product_overview'] = preg_replace($transBeginTag, "", $row['product_overview']);
$row['product_overview'] = preg_replace($transEndTag, "", $row['product_overview']);

Post if you have problems.

One thing of note that I forgot to mention earlier is that you'll want to block all your translations of a single language together.

For example:
Code:
[english] English goes here.[/english]
[spanish]Espanol goes here [/spanish]
[english] english 2nd phrase [/english]
Only the "english 2nd phrase" will show up if english is the selected language.
« Last Edit: March 12, 2010, 04:32:57 AM by intercel » Logged
Pages: [1]
  Print  
 
Jump to: