Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Language flags - hide active language flag or lighten it


Fyod

Recommended Posts

Hi guys.

I'm basing this on the currency flag addon http://www.oscommerce.com/forums/topic/232870-contrib-display-currency-flag-images-instead-of-drop-down-box/

I have a couple languages available. What I want is the flags to either show the active language lightened or for the active icon not be available.

So far, I've updates sql to accomodate the two flag files, added code to enter them in admin. All that works fine.

But it doesn't work in the frontend. In my opinion, /boxes/languages.php doesn't know which language is active.

 

Here's the code

 

 

<!-- languages //-->
<?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;
}
$languages_string = '';
reset($lng->catalog_languages);
while (list($key, $value) = each($lng->catalog_languages)) {
if( $language == $key )
$languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image1'], $value['name']) . '</a> ';
else
$languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image2'], $value['name']) . '</a> ';
$languages_string .= '';
}
$info_box_contents[] = array('align' => 'center',
'text' => $languages_string);
new infoBox($info_box_contents);
?>
<!-- languages_eof //-->

 

It always returns the else (image2), but never image1.

Therefore I think there has to be something wrong with if( $language == $key ).

 

Any help is appreciated!

Link to comment
Share on other sites

If your language is English, application_top.php should have set $language to 'english' and $languages_id to something like "1". What kind of values do $key and $value have? If the closest you come is something like 'en', you'd have to figure out how that maps to 'english'. By the way, $language and $languages_id can be rather unexpected, depending on whether the current language setting or the browser setting is picked up (or even if $language is defined at all). This has been discussed many times, and I offered some (untested) code to rewrite that part of application_top.php to use the UQS 'lang' language, the default language, the browser language, and as a last-ditch fallback, English (or another language of your choice).

 

I would suggest keeping the original flag file name for selectable choices, and add a grayedout_ prefix for unselectable choices. That way you don't have separate image1 and image2. You could also make that unselectable choice as a plain image and not an active link:

$languages_string .= ' ' . tep_image(DIR_WS_ICONS . 'grayout_' . $value['image2'], $value['name']);

Link to comment
Share on other sites

$key echos "ende" this is en and de (the two languages).

$value echos "ArrayArray"

 

Somethin'gs wrong somewhere, I don't see anything duplicated in the code though.

Link to comment
Share on other sites

hi

 

use print_r() on $value to see what's there

 

As Phil says you should have something like 'english' in $language so your line

if( $language == $key )

 

May fail as it's looking like it's trying english == en that should kick in the bit after 'else'

 

also the code you have shown is like below are you missing braces?

 

if( $language == $key )
$languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image1'], $value['name']) . '</a> ';
else
$languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image2'], $value['name']) . '</a> ';
$languages_string .= '';
}

 

Try this with braces - it should at least return 'Did we get here' and if there's still no image then check the path to the image

if( $language == $key ){
$languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image1'], $value['name']) . '</a> ';
}else{
$languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image2'], $value['name']) . '</a> ';
}
$languages_string .= 'Did we get here?';
}

Link to comment
Share on other sites

$key echos "ende" this is en and de (the two languages).

$value echos "ArrayArray"

Try $key[0] and $key[1] and see if you get 'en' and 'de' separately. You'll still have to map 'en' to 'english', or whatever the flag image name is (maybe you could rename the image file to 'en' from 'english'?).

 

Try $value[0], $value[1], $value[0][0], $value[0][1], $value[1][0], and $value[1][1] and see if you get anything recognizable.

Link to comment
Share on other sites

hi

 

use print_r() on $value to see what's there

 

As Phil says you should have something like 'english' in $language so your line

if( $language == $key )

 

May fail as it's looking like it's trying english == en that should kick in the bit after 'else'

 

also the code you have shown is like below are you missing braces?

 

if( $language == $key )
$languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image1'], $value['name']) . '</a> ';
else
$languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image2'], $value['name']) . '</a> ';
$languages_string .= '';
}

 

Try this with braces - it should at least return 'Did we get here' and if there's still no image then check the path to the image

if( $language == $key ){
$languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image1'], $value['name']) . '</a> ';
}else{
$languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image2'], $value['name']) . '</a> ';
}
$languages_string .= 'Did we get here?';
}

 

With the second quoted code I get

[flag image2 language1] Did we get here? [flag image2 language2] Did we get here?

 

So both languages are ok, but it's using the second string, which is the "faded" image that means this language is the one currently shown. In this case, [flag image2 language1] should be image1 (not faded). Or if i click on it (indeed switches languages correctly) the fade/unfade should switch on both, relative to whether it is currently used or not.

But both links are ok, lead to the correct language, work fine. So it's just a matter of getting the currently not used language version to show the unfaded image (first string).

I hope this description is comprehensible :)

 

The extra braces make no difference. I mostly copied this part from the currency box and that one works ok, also without the mentioned braces.

Pictures are ok and linked ok also.

 

Try $key[0] and $key[1] and see if you get 'en' and 'de' separately. You'll still have to map 'en' to 'english', or whatever the flag image name is (maybe you could rename the image file to 'en' from 'english'?).

 

Try $value[0], $value[1], $value[0][0], $value[0][1], $value[1][0], and $value[1][1] and see if you get anything recognizable.

 

I now see that ende was ok because it just showed the two strings and there was no space or anything between them.

The [x] don't change a thing.

So basically the only thing wrong is that the code always skips the string containing image1.

I've also checked classes/languages.php to see if image1 and image2 are correct and they are. So it's not a matter of the first string returning the wrong image, the first string gets ignored no matter what.

 

I should also note that the currency flags (separate code) are being shown along with the language flags and work ok. Even the set default currencies switch themselves (and images) accordingly.

Link to comment
Share on other sites

Just noticed this

 

 while (list($key, $value) = each($lng->catalog_languages)) {
 if( $language == $key )
 $languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image1'], $value['name']) . '</a> ';
 else
 $languages_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_ICONS . $value['image2'], $value['name']) . '</a> ';
 $languages_string .= $key;

 

I get:

 

[image2 lang1] en

[image2 lang2] de

 

(both link to the correct language and display correct, but faded images)

 

So the $key seems to also be working fine.

 

but

 

$key returns 'en', $language returns 'english'

so for $language == $key to work, I need $key to not be the id, rather the directory name

Link to comment
Share on other sites

That's what I was telling you that you might have to do: some kind of mapping from en to english or vice-versa. Do you really have to go into a directory named 'english', or are you just looking for a flag image file? If the latter, just rename english.gif (or whatever it is) to en.gif, and you can use $key. Otherwise, you have to have a lookup array $dirname['en'] = 'english' type thing.

Link to comment
Share on other sites

I don't think its a matter of imagename or directory.

$key seems to originate from the language 2-letter code, while $language is originates from broweser languages and $lng (ie. en|english) both from the classes/language.php.

So yes, it seems best to translate $key back to a full language name.

Link to comment
Share on other sites

Solved!

  if( $language == $value['name'] )

 

All that needs to be changed then is that in admin - languages, the language title has to be the same as the language directory.

Link to comment
Share on other sites

2.3.3

 

while (list($key, $value) = each($currencies->currencies)) {
	    if ($key == $currency) {
		  // image at full strength as this is the language right now
		  $currencies_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language', 'currency')) . 'currency=' . $key) . '">' . tep_image(DIR_WS_ICONS . $key . '.png', $value['title']) . '</a> ';
	    }
	    else {
		  // fade the image as these are the unused images
		  $currencies_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language', 'currency')) . 'currency=' . $key) . '">' . tep_image(DIR_WS_ICONS . $key . '.png', $value['title'], '', '', 'style="opacity:0.4; filter:alpha(opacity=40);"') . '</a> ';
	    }
	  }

 

Save files into /images/icons/ called USD.png EUR.png and so on.

Link to comment
Share on other sites

That would work also, but in my case, 2 languages - 2 currencies, one of the languages has an option of both currencies. So I don't want a combined currency/language flag.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...