Zen Cart Logo
Forums / General Questions / A multilingual store

A multilingual store

Locked

Views: 4,953

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
11 Aug 2006, 6:02 AM
#1
g_nencini avatar

g_nencini

Zen Follower

Join Date:
Mar 2006
Location:
Florence, Italy
Posts:
153
Plugin Contributions:
0

A multilingual store

First of all excuse me for my very bad english, and try to understand what I mean.
I'm building a multilingual store (english, italian, french & spanish) and I want to show to the community the problems I met and the solutions I've taken.

1 - Controll the scripts with the define(......) statements

The first thing to do when we have installed a new language is to controll and compare all the scripts that contain the define(......) statements, in the store and in the admin sections. Very often happen that some definitions are not present, and somtimes have different names.
So, taking the english as base-language, we mus controll all other languages.

2 - How detect the actual language

The variable $_SESSION['languages_id']; contains a number that identifies the language. That number is "the order of installation of the languages", and so if I write same new code, I must know it. More, if I want give my code to a friend, he may have problems.
So I've defined a constant (in the store and in the admin section) in this way:

include\languages\english.php --> define('ACTUAL_LANGUAGE', 'en');
include\languages\italian.php --> define('ACTUAL_LANGUAGE', 'it');
include\languages\french.php --> define('ACTUAL_LANGUAGE', 'fr');
include\languages\spanish.php --> define('ACTUAL_LANGUAGE', 'sp');

and when I need, I use the constant ACTUAL_LANGUAGE instead of the $_SESSION['languages_id'].

3 - The function zen_date_long in the store

I had many problems with the statement @setlocale(LC_TIME, .........'); and so I've modified the function zen_date_long for not becoming crazy. You can see that on the file functions_general.php in attachments. Note that I've not use directly the $day, $month, $year indexes, because the two functions mktime and getdate may correct errors (32 dec. becomes 1 jan.)

4 - The function zen_date_long in the admin

As you can see in the attacments, the function zen_date_long in the admin (general.php) is very similar to the function in the store, but there is the parameter $language='no'.
For the moment ignore this parameter (we'll see later, in the next thread) but notice that the function may be called also with only the first parameter, and that the control is made first to the existance of the $language.

5 - Modifying the script include\modules\new_products.php

I've decided that a new product remains "new" for 60 days, an so I want that in the intest of the table is written, for example, "New Products For July-August". You can see in the attachments how this is performed.

6 - Modifying the script include\modules\specials_index.php

The changements in the specials are now very simple to understand See it in the attachments.

In the next thread I'll write on the language problem for the e-mail sent to a costumer when in the section "admin" is changed the status of an order.

Regards to everybody - Giovanni

11 Aug 2006, 7:43 PM
#2
ryanp avatar

ryanp

Zen Follower

Join Date:
Nov 2004
Location:
Germany
Posts:
94
Plugin Contributions:
0

Re: A multilingual store

Very interesting, Zen-Cart still has a bit to do in regards to truly handling multiple languages. It's workable at the momment but your tips improve it quite a bit.

Keep up the good work.

12 Aug 2006, 3:53 AM
#3
g_nencini avatar

g_nencini

Zen Follower

Join Date:
Mar 2006
Location:
Florence, Italy
Posts:
153
Plugin Contributions:
0

Re: A multilingual store

The problem

When in the admin section we change the state of an order (for example from Pending to Processing) zen-cart send to the costumer an e-mail for informing of the new situation. Unfortunately the language of the e-mail is the language selected in the admin section, and not the language with which the costumer have made the order. This is not a simple problem, because in php a constant (ACTUAL_LANGUAGE) can't be dropped or redefined.
Now I'll show step by step "my solution", but I hope there are others more simple!

Step 1 - Add a field to the table "orders"

To build a proper reply, we must know the language with which the costumer have made the order, and so we'll add a field to the table "orders":

orders_language_id -- varchar(8) -- NOT NULL -- default 'en'

Then we'll add to the includes/classes/order.php - row 631 the component of the $sql_data_array

'orders_language_id' => ACTUAL_LANGUAGE

In this way all the orders will carry on the proper language.

Step 2 - Detecting the language in admin/orders.php

The script admin/orders.php, after the row 100, prepare the data for the e-mail. We must replace the constant with variables, and then, first of all, we detect the language of the order (row 102):

$pippo = $db->Execute("select orders_language_id from "
. TABLE_ORDERS . " where orders_id='" . $oID . "'");
$custolang =$pippo->fields['orders_language_id'];

Now the variable $custolang contains the language we must use.

Step 3 - Writing the script admin/orders_email.php

As you can see in the attachements, the script orders_email.php that I've written, contains 3 funcions:

modify_language_for_email($lang) --> messages
modify_status_for_email($lang) --> name of the status
show_greeting_for_email($lang,$gen='x') --> Replace the word "Dear" in the e-mail

  • The $a returned from modify_language_for_email($lang) is an "associative array" where the keys have the same name of the relative constant, so we can make the replacements easily.

  • Adding the $c to the $check_status->fields['customers_name'] (row 122) we must cancel the word "Dear" in email/email_template_order_status.html.
    The function show_greeting_for_email is ready to accept a second parameter: we could add another field to the table "orders" with the sex of the costumer.

Step 4 - First replacements in admin/orders.php

Now we let the admin/orders.php to know the admin/orders_email.php with the statement of the row 23

require('orders_email.php');

and after we can get the two arrays and the variable (row 106):

$a = modify_language_for_email($custolang);
$b = modify_status_for_email($custolang);
$c = show_greeting_for_email($custolang);

and make the replacements as

EMAIL_TEXT_ORDER_NUMBER ---> $a['EMAIL_TEXT_ORDER_NUMBER']
$orders_status_array[$status] ---> $b[$status]

Now we must remember how we have modified the function zen_date_long of the admin section (see the thread #1)and so we can replace:

zen_date_long($check_status->fields['date_purchased']) with
zen_date_long($check_status->fields['date_purchased'],$custolang)

and so also the date will be in the customer's language.

Step 5 - Problems of EMAIL_DISCLAIMER and EMAIL_SPAM_DISCLAIMER

At the rows 132 and 137 the script admin/orders.php call he function zen_mail that is in includes/functions/functions_email.php of the store section.
The zen_mail, at the row 76, call the zen_build_html_email_from_template, and is just in this function that are added the EMAIL_DISCLAIMER and EMAIL_SPAM_DISCLAIMER.

So we must go to the zen_build_html_email_from_template passing through the zen_mail.
But the zen_mail has 9 parameters, and the last one ($attachments_list='') is not called in the admin/orders.php, so, for respecting the orders of the parameters, we'll define a variable $null=''; and at this point:

  • we'll add the 3 parameters $null, $a['EMAIL_DISCLAIMER'] and $a['EMAIL_SPAM_DISCLAIMER']) at the end of callig zen_mail (rows 132 & 137 of admin/orders.php)

  • we'll add the parameters $aa='' and Sbb='' to the two function's definitions zen_mail and zen_build_html_email_from_template (so they can be called also without this parameters)

  • we'll add the parameters $aa and Sbb in the call to the zen_build_html_email_from_template (row 76 of the includes/functions/functions_email.php) so the two strings will passed to this function.

  • we'll let the function to work properly in all the situations (row 283) adding the code

if($aa != '' && $bb != '')
{
$email_disclaimer = $aa;
$email_spam_disclaimer = $bb;
}else{
$email_disclaimer = EMAIL_DISCLAIMER;
$email_spam_disclaimer = EMAIL_SPAM_DISCLAIMER;
}

and replacing

EMAIL_DISCLAIMER ---> $email_disclaimer (row 324)
EMAIL_SPAM_DISCLAIMER ---> $email_spam_disclaimer (row 325)

This is "The end". I've made some tests, and all seems to work well.
However what I don't like in this solution is that in the admin/orders_email.php I had to reply (copy) the strings that are present in other parts of the package, but I've not found another solution.

Regards to everybody - Giovanni

13 Aug 2006, 3:50 AM
#4
g_nencini avatar

g_nencini

Zen Follower

Join Date:
Mar 2006
Location:
Florence, Italy
Posts:
153
Plugin Contributions:
0

Re: A multilingual store

Note to the function include\classes\order.php

There is another modification that I've made to the include\classes\order.php that I've not mentioned before.

At the end of the 3 steps of the check-out for an order, the script include\classes\order.php send to the costumer an e-mail with all the data of the order, included the current date.
This date was defined with the statement

strftime(DATE_FORMAT_LONG);

From row 18 to row 58 I have modified the script to show the date in the proper language using the function call

$today = getdate();

and making the usual check on the language.
So I have made the replacemens:

Row 903:
// EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n" .
EMAIL_TEXT_DATE_ORDERED . ' ' . $today . "\n" .

Row 913:
// $html_msg['INTRO_DATE_ORDERED'] = strftime(DATE_FORMAT_LONG);
$html_msg['INTRO_DATE_ORDERED'] = $today;

Regards to everybody - Giovanni