Utilizzare la variabile $language

Postate qui discussioni di carattere generale riguardo a problemi di installazione e configurazione di osCommerce

Moderatore: mod Generali

Rispondi
bassone
membro Junior
membro Junior
Messaggi: 11
Iscritto il: 03/10/2003, 0:00
Località: USA

Utilizzare la variabile $language

Messaggio da bassone »

ciao a tutti, scusate ma sto' impazzendo nel modificare una parte di osc. Qualche tempo fa ho installato e modificato un template per un cliente, e tutto e' andato benissimo, osc era solo in lingua italiana, ora il cliente vuole implementare anche la lingua inglese, purtroppo i link e le immagini poste nella header.php sono fisse, e non cambiano con il cambiare della lingua, ora avevo pensato di usare un semplice IF per risolvere il problema tipo questa:

<?php

if ($languages = "it") {
include ('ita.php');
} else {
include ('eng.php');
}

?>

mi sembrava la soluzione piu' semplice, ma non riesco a farlo funzionare, forse sbaglio ad utilizzare la variabile, o forse sono arrugginito, ma vi giuro che sto' diventando matto...
qualcuno ha un idea ???

grazie a tutti
Maipiusenza
membro Regular
membro Regular
Messaggi: 117
Iscritto il: 06/06/2006, 13:34
Località: Monopoli (BA)
Contatta:

Re: Utilizzare la variabile $language

Messaggio da Maipiusenza »

bassone ha scritto:...
if ($languages = "it") {
...
if ($languages == "it") {

Ciao
Nadia
Non rompere le scatole... Aprile!!! :-P
www.maipiusenza.com
bassone
membro Junior
membro Junior
Messaggi: 11
Iscritto il: 03/10/2003, 0:00
Località: USA

Messaggio da bassone »

grazie, non avevo visto l'errore, ma dopo troppe ore qui davanti mi fumano.... anche cosi' pero' nulla, i menu nella header, anche cambiando lingua restano sempre nella medesima, qualche idea ???

ciao grazie
Avatar utente
marcus
membro Master
membro Master
Messaggi: 1619
Iscritto il: 04/12/2003, 1:00
Contatta:

Messaggio da marcus »

bassone ha scritto:grazie, non avevo visto l'errore, ma dopo troppe ore qui davanti mi fumano.... anche cosi' pero' nulla, i menu nella header, anche cambiando lingua restano sempre nella medesima, qualche idea ???

ciao grazie
Posta header.php completo.

Saluti
Marcus
Nuovo pacchetto osCommercePRO (osCPRO) + Modulo Interfacciamento Gestionale Danea.
Visita la demo: http://oscpro.oscommercedev.com/index.php
bassone
membro Junior
membro Junior
Messaggi: 11
Iscritto il: 03/10/2003, 0:00
Località: USA

Messaggio da bassone »

ecco header. php

<?php
/*
$Id: header.php,v 1.42 2003/06/10 18:20:38 hpdl Exp $

osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com

Copyright (c) 2003 osCommerce

Released under the GNU General Public License
*/

// check if the 'install' directory exists, and warn of its existence
if (WARN_INSTALL_EXISTENCE == 'true') {
if (file_exists(dirname($HTTP_SERVER_VARS['SCRIPT_FILENAME']) . '/install')) {
$messageStack->add('header', WARNING_INSTALL_DIRECTORY_EXISTS, 'warning');
}
}

// check if the configure.php file is writeable
if (WARN_CONFIG_WRITEABLE == 'true') {
if ( (file_exists(dirname($HTTP_SERVER_VARS['SCRIPT_FILENAME']) . '/includes/configure.php')) && (is_writeable(dirname($HTTP_SERVER_VARS['SCRIPT_FILENAME']) . '/includes/configure.php')) ) {
$messageStack->add('header', WARNING_CONFIG_FILE_WRITEABLE, 'warning');
}
}

// check if the session folder is writeable
if (WARN_SESSION_DIRECTORY_NOT_WRITEABLE == 'true') {
if (STORE_SESSIONS == '') {
if (!is_dir(tep_session_save_path())) {
$messageStack->add('header', WARNING_SESSION_DIRECTORY_NON_EXISTENT, 'warning');
} elseif (!is_writeable(tep_session_save_path())) {
$messageStack->add('header', WARNING_SESSION_DIRECTORY_NOT_WRITEABLE, 'warning');
}
}
}

// check session.auto_start is disabled
if ( (function_exists('ini_get')) && (WARN_SESSION_AUTO_START == 'true') ) {
if (ini_get('session.auto_start') == '1') {
$messageStack->add('header', WARNING_SESSION_AUTO_START, 'warning');
}
}

if ( (WARN_DOWNLOAD_DIRECTORY_NOT_READABLE == 'true') && (DOWNLOAD_ENABLED == 'true') ) {
if (!is_dir(DIR_FS_DOWNLOAD)) {
$messageStack->add('header', WARNING_DOWNLOAD_DIRECTORY_NON_EXISTENT, 'warning');
}
}

if ($messageStack->size('header') > 0) {
echo $messageStack->output('header');
}
?>


<table cellspacing=0 cellpadding=0 width=674 align=center>
<tr><td>
<table cellspacing=0 cellpadding=0>
<tr><td><a href=<?=tep_href_link('index.php')?>><img src=images/m01.gif width=231 height=106 border=0></a></td>
<td width=60></td>
<td><img src=images/m02.gif width=143 height=106></td>
<td width=118>
<table cellspacing=0 cellpadding=0>
<tr><td height=25 colspan=2></td></tr>
<tr><td colspan=2>

<? // LANGUAGES

if (!isset($lng) || (isset($lng) && !is_object($lng))) {
include(DIR_WS_CLASSES . 'language.php');
$lng = new language;
}

$languages_string = '';
reset($lng->catalog_languages);
while (list($key, $value) = each($lng->catalog_languages)) {
$languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language', 'currency')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_LANGUAGES . $value['directory'] . '/images/' . $value['image'], $value['name']) . '</a> ';
}

echo $languages_string;

?>

</td></tr>
<tr><td height=13 colspan=2></td></tr>
<tr><td colspan=2><img src=images/m17.gif width=103 height=1></td></tr>
<tr><td height=13 colspan=2></td></tr>
<tr><td rowspan=2><a href=<?=tep_href_link('shopping_cart.php')?>><img src=images/m07.gif width=20 height=20 border=0></a></td><td> <b>Shopping bag</b></td></tr>
<tr><td colspan=2> <b><a href=<?=tep_href_link('shopping_cart.php')?> class=ml><?=$cart->count_contents()?> items</a></b></td></tr>
</table>
</td>
<td><img src=images/m16.gif width=1 height=85></td>
<td width=122>
<?php

if ($languages == "en") {
include ('eng.php');
} else {
include ('ita.php');
}

?>
</td></tr>
</table>
<table cellspacing=0 cellpadding=0>
<tr><td><img src=images/m08.gif width=675 height=5></td></tr>
</table>
<table cellspacing=0 cellpadding=0>
<tr><td width=206 valign=top>
<table cellspacing=0 cellpadding=0>
<tr><td height=7></td></tr>
<tr><td><a href=<?=tep_href_link('index.php')?>><img src=images/m11.gif width=206 height=27 border=0></a></td></tr>
<tr><td><a href=<?=tep_href_link('account.php')?>><img src=images/m12.gif width=206 height=28 border=0></a></td></tr>
<tr><td><a href=<?=tep_href_link('products_new.php')?>><img src=images/m13.gif width=206 height=27 border=0></a></td></tr>
<tr><td><a href=<?=tep_href_link('shopping_cart.php')?>><img src=images/m14.gif width=206 height=27 border=0></a></td></tr>
<tr><td><a href=<?=tep_href_link('checkout_shipping.php')?>><img src=images/m15.gif width=206 height=27 border=0></a></td></tr>
<tr><td height=4></td></tr>
</table>
</td>
<td width=25></td>
<td width=444><a href=<?=tep_href_link('products_new.php')?>><img src=images/m10.jpg width=203 height=147 border=0><img src=images/m09.jpg width=241 height=147 border=0></a></td></tr>
<tr><td colspan=3 height=1></td></tr>
<tr><td colspan=3 height=4 bgcolor=#E6E6E6 width=674></td></tr>
<tr><td colspan=3 height=6></td></tr>
</table>
<table cellspacing=0 cellpadding=0>
<tr><td width=229 valign=top>
<table cellspacing=0 cellpadding=0>
<tr><td background=images/m19.gif width=229 height=36 class=bc>         <b>Browse by Categories:</b></td></tr>
<tr><td class=bg>
<table cellspacing=0 cellpadding=0 width=195 align=center>
<tr><td height=17></td></tr>

<? // ---- CATEGORIES

function tep_show_category($counter) {
global $tree, $categories_string, $cPath_array;

if(!$tree[$counter]['level']){
$categories_string .= $categories_string ? '<tr><td colspan=2><img src=images/m21.gif width=195 height=1><br><br class=px3></td></tr>' : '';

$categories_string .= '<tr><td width=39 align=center><img src=images/m06.gif width=5 height=5></td><td width=156><a class=ml href=';

if ($tree[$counter]['parent'] == 0) {
$cPath_new = 'cPath=' . $counter;
} else {
$cPath_new = 'cPath=' . $tree[$counter]['path'];
}
$categories_string .= tep_href_link('index.php', $cPath_new) . '>';
// display category name
$categories_string .= $tree[$counter]['name'];
$categories_string .= '</a><br><br class=px3></td></tr>';
}else{
$categories_string .= '<tr><td width=39 align=center></td><td width=156>';

for($i=0;$i<$tree[$counter]['level'];$i++)
$categories_string .= ' ';

$categories_string .= '- <a class=ml href=';
if ($tree[$counter]['parent'] == 0) {
$cPath_new = 'cPath=' . $counter;
} else {
$cPath_new = 'cPath=' . $tree[$counter]['path'];
}
$categories_string .= tep_href_link('index.php', $cPath_new) . '>';
// display category name
$categories_string .= $tree[$counter]['name'];
$categories_string .= '</a><br><br class=px3></td></tr>';
}

if ($tree[$counter]['next_id'] != false) {
tep_show_category($tree[$counter]['next_id']);
}
}



define(TABLE_CATEGORIES, "categories");
define(TABLE_CATEGORIES_DESCRIPTION, "categories_description");
$categories_string = '';
$tree = array();

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
while ($categories = tep_db_fetch_array($categories_query)) {
$tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
'parent' => $categories['parent_id'],
'level' => 0,
'path' => $categories['categories_id'],
'next_id' => false);

if (isset($parent_id)) {
$tree[$parent_id]['next_id'] = $categories['categories_id'];
}

$parent_id = $categories['categories_id'];

if (!isset($first_element)) {
$first_element = $categories['categories_id'];
}
}

//------------------------
if ($cPath) {
$new_path = '';
reset($cPath_array);
while (list($key, $value) = each($cPath_array)) {
unset($parent_id);
unset($first_id);
$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
if (tep_db_num_rows($categories_query)) {
$new_path .= $value;
while ($row = tep_db_fetch_array($categories_query)) {
$tree[$row['categories_id']] = array('name' => $row['categories_name'],
'parent' => $row['parent_id'],
'level' => $key+1,
'path' => $new_path . '_' . $row['categories_id'],
'next_id' => false);

if (isset($parent_id)) {
$tree[$parent_id]['next_id'] = $row['categories_id'];
}

$parent_id = $row['categories_id'];

if (!isset($first_id)) {
$first_id = $row['categories_id'];
}

$last_id = $row['categories_id'];
}
$tree[$last_id]['next_id'] = $tree[$value]['next_id'];
$tree[$value]['next_id'] = $first_id;
$new_path .= '_';
} else {
break;
}
}
}
$categories_string .= '';
tep_show_category($first_element);
$categories_string .= '';

echo $categories_string;
?>

<tr><td colspan=2 height=16></td></tr>
</table>

<? // ---- MANUFACTURERS




$manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
if ($number_of_rows = tep_db_num_rows($manufacturers_query)) {

echo ' <table cellspacing=0 cellpadding=0>'.
tep_draw_form('manufacturers', tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false), 'get')
.'<tr><td background=images/m19.gif width=229 height=36 class=bc>         <b>Browse by Brand:</b></td></tr>
<tr><td>
<table cellspacing=0 cellpadding=0 width=195 align=center>
<tr><td colspan=2 height=20></td></tr>
<tr><td align=right>
';

$manufacturers_array = array();
while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
$manufacturers_name = ((strlen($manufacturers['manufacturers_name']) > MAX_DISPLAY_MANUFACTURER_NAME_LEN) ? substr($manufacturers['manufacturers_name'], 0, MAX_DISPLAY_MANUFACTURER_NAME_LEN) . '..' : $manufacturers['manufacturers_name']);
$manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
'text' => $manufacturers_name);
}

echo tep_draw_pull_down_menu('manufacturers_id', $manufacturers_array, (isset($HTTP_GET_VARS['manufacturers_id']) ? $HTTP_GET_VARS['manufacturers_id'] : ''), 'onChange="this.form.submit();" size="' . MAX_MANUFACTURERS_LIST . '" class=se') . tep_hide_session_id();
echo ' </td><td align=left valign=top> <input type=image src=images/m23.gif width=34 height=19></td></tr>
<tr><td colspan=2 height=20></td></tr>
</table>
</td></tr>
</form>
</table>
';


}
?>
<tr><td><img src=images/m22.gif width=229 height=3></td></tr>
<tr><td height=1></td></tr>
<tr><td><a href=<?=tep_href_link('index.php', 'cPath=50')?>><img src=images/m18.jpg width=229 height=98 border=0></a></td></tr>
</td></tr>
</table>

</td>
<td width=10></td>
<td width=445 valign=top>
bassone
membro Junior
membro Junior
Messaggi: 11
Iscritto il: 03/10/2003, 0:00
Località: USA

Messaggio da bassone »

queste le parti di codice mancanti sostituite da IF

eng.php

<table cellspacing=0 cellpadding=0 width=96 align=center>
<tr><td height=16></td></tr>
<tr><td><img src=images/m06.gif width=5 height=5 align=absmiddle>   <a href=<?=tep_href_link('specials.php')?> class=ml1>Specials</a><br><br class=px2></td></tr>
<tr><td><img src=images/m06.gif width=5 height=5 align=absmiddle>   <a href=<?=tep_href_link('advanced_search.php')?> class=ml1>Search</a><br><br class=px2></td></tr>
<tr><td><img src=images/m06.gif width=5 height=5 align=absmiddle>   <a href=<?=tep_href_link('contact_us.php')?> class=ml1>Contact Us</a><br><br class=px2></td></tr>
<tr><td><img src=images/m06.gif width=5 height=5 align=absmiddle>   <a href=<?=tep_href_link('create_account.php')?> class=ml1>Create an account</a><br><br class=px2></td></tr>
<tr><td><img src=images/m06.gif width=5 height=5 align=absmiddle>   <a href=<?=tep_href_link('login.php')?> class=ml1>Customer Login</a><br><br></td></tr>
</table>

ita.php

<table cellspacing=0 cellpadding=0 width=96 align=center>
<tr><td height=16></td></tr>
<tr><td><img src=images/m06.gif width=5 height=5 align=absmiddle>   <a href=<?=tep_href_link('specials.php')?> class=ml1>Speciale</a><br><br class=px2></td></tr>
<tr><td><img src=images/m06.gif width=5 height=5 align=absmiddle>   <a href=<?=tep_href_link('advanced_search.php')?> class=ml1>Cerca</a><br><br class=px2></td></tr>
<tr><td><img src=images/m06.gif width=5 height=5 align=absmiddle>   <a href=<?=tep_href_link('contact_us.php')?> class=ml1>Contatto</a><br><br class=px2></td></tr>
<tr><td><img src=images/m06.gif width=5 height=5 align=absmiddle>   <a href=<?=tep_href_link('create_account.php')?> class=ml1>Nuovo account</a><br><br class=px2></td></tr>
<tr><td><img src=images/m06.gif width=5 height=5 align=absmiddle>   <a href=<?=tep_href_link('login.php')?> class=ml1>Login</a><br><br></td></tr>
</table>
Avatar utente
marcus
membro Master
membro Master
Messaggi: 1619
Iscritto il: 04/12/2003, 1:00
Contatta:

Messaggio da marcus »

Mi pare che le parti che cambiano con la lingua siano solo testo, per cui puoi risolvere semplicemente introducendo delle costanti di lingua in italian.php e english.php, per le parole che variano con la lingua.

In ogni caso se vuoi mantenere due file separati eng.php e ita.php,
prova a sostituire:

Codice: Seleziona tutto

if ($languages == "en") {
include ('eng.php');
} else {
include ('ita.php');
} 
con

Codice: Seleziona tutto

switch ($language) {

case: 'english':
include ('eng.php');
break;

case 'italian' :
include ('ita.php');
break;

default:
include ('ita.php');

} 
Okkio che $languages ->diventa-> $language :wink:

Eventualmente posta anche il file application_top.php.

Saluti
Marcus
Nuovo pacchetto osCommercePRO (osCPRO) + Modulo Interfacciamento Gestionale Danea.
Visita la demo: http://oscpro.oscommercedev.com/index.php
Rispondi