Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

how to change language box to dropdown menu?


minglou

Recommended Posts

I couldn't tell you EXACTLY how to do it, but try looking at the

./catalog/includes/boxes/languages.php

and

./catalog/includes/boxes/currencies.php

files

 

compare them and copy code from currencies to languages. replace all the references to the currencies variables with the language variables.

 

hope that helps... i haven't been getting much help in this forum... people won't even respond to my questions. overall i've found this community very "cold."

i'm just trying to do my part.

-Mark

 

Hi guys,

 

How can i change the current language box to dropdown menu?

 

just like currency box.

 

Thanks

 

sean

Link to comment
Share on other sites

Hi Sean,

 

I was about to tell you to look up the forums for this or to search the contributions, however it's just one of those questions that nobody has given a solution to this over the years - dunno why !!

 

Anyway it took a bit of working out but here is your solution replace the contents of your

catalog/includes/boxes/languages.php with the following code.

<?php
/*
 $Id: languages.php,v 1.15 2003/06/09 22:10:48 hpdl Exp $

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

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/
?>
<!-- languages //-->
         <tr>
           <td>
<?php
 $info_box_contents = array();
 $info_box_contents[] = array('text' => BOX_HEADING_LANGUAGES);

 new infoBoxHeading($info_box_contents, false, false);

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

 reset($lng->catalog_languages);
 $languages_array = array();

// Hack by Philip Hennessy for
// drop down Languages Box
 while (list($key, $value) = each($lng->catalog_languages)) {
     $languages_array[] = array('id' => $key, 'text' => $value['name']);
   }

   $hidden_get_variables = '';
   reset($HTTP_GET_VARS);
   while (list($key, $value) = each($HTTP_GET_VARS)) {
     if ( ($key != 'language') && ($key != tep_session_name()) && ($key != 'x') && ($key != 'y') ) {
       $hidden_get_variables .= tep_draw_hidden_field($key, $value);
     }


/*    $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> ';  */


 }

 $info_box_contents = array();
   $info_box_contents[] = array('form' => tep_draw_form('languages', tep_href_link(basename($PHP_SELF), '', $request_type, false), 'get'),
                                'align' => 'center',
                                'text' => tep_draw_pull_down_menu('language', $languages_array, $language, 'onChange="this.form.submit();" style="width: 100%"') . $hidden_get_variables . tep_hide_session_id());

   new infoBox($info_box_contents);

// End of Hack !!

?>
           </td>
         </tr>
<!-- languages_eof //-->

 

Now the only thing I can't seem to get at the moment is for the current language to be on top of the list. But I'll get back to you on this.

 

Hope this helps

 

Regards

PhilipH

Link to comment
Share on other sites

  • 7 months later...

Hi!

Me too needed languages drop down menu.

I try change currensy.php and it works, but i can't set current language in drop down menu as selected.

I find variable $language with current lang, but cannot convert hi to lang code.

 

For exsample, if $language = 'english' or 'russian', i get 2 first letters and fave lang code ('en', 'ru'), but if $language = 'german' or 'czech' for samle then two first letters geves wrong lang code ('ge', 'cz' instead 'de' or 'cs')

 

Anybody can help me?

 

Here is my code:

 

<!-- languages //-->
	  <tr>
		<td>
<?php

 $info_box_contents = array();
 $info_box_contents[] = array('text' => BOX_HEADING_LANGUAGES);

 new infoBoxHeading($info_box_contents, false, false);

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

 $cur_lang = '';
 $cur_lang = substr($language,0,2);

 while (list($key, $value) = each($lng->catalog_languages)) {
$languages_array[] = array('id' => $key, 'text' => $value['name']);
 }

 $info_box_contents = array();

 $info_box_contents[] = array('form' => tep_draw_form('language', tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false), 'get'),
							  'text' => tep_draw_pull_down_menu('language', $languages_array, (isset($HTTP_GET_VARS['language']) ? $HTTP_GET_VARS['language'] : $cur_lang), 'onChange="this.form.submit();" style="width: 100%"') . tep_hide_session_id());
 new infoBox($info_box_contents);
?>
		</td>
	  </tr>
<!-- languages_eof //-->

Link to comment
Share on other sites

I did it, this is working code:

 

<?php
 $info_box_contents = array();
 $info_box_contents[] = array('text' => BOX_HEADING_LANGUAGES);

 new infoBoxHeading($info_box_contents, false, false);

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

 $cur_lang = '';
 while (list($key, $value) = each($lng->catalog_languages)) {
$languages_array[] = array('id' => $key, 'text' => $value['name']);
if ($value['id'] == $languages_id) $cur_lang = $key;
 }

 $info_box_contents = array();

 $info_box_contents[] = array('form' => tep_draw_form('language', tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false), 'get'),
							  'text' => tep_draw_pull_down_menu('language', $languages_array, (isset($HTTP_GET_VARS['language']) ? $HTTP_GET_VARS['language'] : $cur_lang), 'onChange="this.form.submit();" style="width: 100%"') . tep_hide_session_id());
 new infoBox($info_box_contents);
?>

Link to comment
Share on other sites

  • 2 years later...

I also just looked for a "Drop-Down Language" contribution, but couldn't find one. thank you for the solution. it is quite simple to fix the problem to show the current language all the way long from choosing the language to the checkout. just set your shop on iso-code which is also used by paypal. therefor you rename all language folder in catalog/includes/language/ and catalog/admin/language/ from now possibily "english" to "gb", "german" to "de" and so on. for that you better use dreamweaver or another software which automaticaly check and update also the files within the folders .. then rename alle language.php files as well .. english.php into gb.php, german.php into de.php and so on .. start the upload of the language directories, smoke a cigarette, kick the dog or just leave the house as long as the upload is in progress .. and better NOT have a look at your shop, because during the upload process it causes a unbelivible number of errors .. after the upload is done the last step is to make some changes within the shop admin. set all languages to the new folders .. done!! .. it takes a while to do all steps, but afterwards your shop is ready for international success and even the websites from PayPal and the credit card companies will show the right language web site if a customer e.g. from France wants to pay his purchase at your shop with Euro and in french language.

 

have fun with it & good sales

greetings from germany

eric

Link to comment
Share on other sites

Hi,

 

Is it also possible to change the language box to normal text looking like the information box?

I've looked for 2 days now, but couldn't find anything.

 

Please help.

 

Chantal

Link to comment
Share on other sites

  • 2 years later...

Hi

I'm trying to re-write it for version 2.3.1

 

anyone else had success

 

$cur_lang = '';
$languages_array = array(); 
while (list($key, $value) = each($lng->catalog_languages)) {
       	$languages_array[] = array('id' => $key, 
									'text' => $value['name']);
       	if ($value['id'] == $languages_id) $cur_lang = $key;
        	}

$data =  '<div style="text-align: right;">' .  
			 '  ' . tep_draw_form('language', tep_href_link(basename($PHP_SELF),  tep_get_all_get_params(array('language', 'currency')) . 'language=' . $key, $request_type) , 'get') . 
			 '  ' . tep_draw_pull_down_menu('language', $languages_array, $cur_lang, 'onchange="this.form.submit();" style="width: 200px"') .  tep_hide_session_id() .				
			  '</form>' . 
			  '</div>';
break;

 

i can get it to work under anther way but it is not what i want due to the verbose code

 

$language_amount_query = mysql_query("select * from " . TABLE_LANGUAGES . " order by 'name'");
     $language_amount_query_test = mysql_query("select * from " . TABLE_LANGUAGES . " order by 'name'");
     $language_amount_numRows = tep_db_num_rows($language_amount_query);
     $language_amount_numRows_test = tep_db_num_rows($language_amount_query_test);
      if(!$language_amount_numRows){error_message(sql_error);}
           $language_html_arr_test = array();
         for($i=0;$i<$language_amount_numRows;$i++){
             $language_html_arr_test[$i] = mysql_fetch_row($language_amount_query_test);
             if($language==$language_html_arr_test[$i][4]){
               $language_local = $language_html_arr_test[$i][1];
             }
           }

<td> <?php tep_image(DIR_WS_LANGUAGES . $language . '/images/icon.gif','','','',' alt="'.BOX_HEADING_LANGUAGES.': '.$language_local.'" style="border:2px solid #D1D1D1;"'); */?></td> 
                 <form id="prismatik.net" name="adminlanguage" action="<?php echo tep_href_link(basename($PHP_SELF)); ?>" method="GET" style="margin:0px; padding:0px;">                           
		<select name="language" onChange="this.form.submit();" class="form_create_ipt">
                     <?php 
                     $language_html_arr = array();
                     for($i=0;$i<$language_amount_numRows;$i++){
                       $language_html_arr[$i] = mysql_fetch_row($language_amount_query);
                       if($language==$language_html_arr[$i][4]){
                         $form_option_selected = 'selected';
                       }else{
                         $form_option_selected = "";
                       }
                       echo '<option  value="'.$language_html_arr[$i][2].'" '.$form_option_selected.'>'.$language_html_arr[$i][1].'</option>'."\n";
                     }
                      ?>
                   </select>
                 </form>

 

Regards

Golith

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...