Hmm this was not easy:
I try once more:
Before the script gets to the usort($browser_langs, ...) then it contains:
no
en
which is the priority of the languages as set in my browser.
After the usort it contains
en
no
Which now does not honor my priority given to no as set in my browser.
Since I have set priority to "no" (norwegian) in my browser then I would like the site to show up in Norwegian pages.
My site is in two languages Norwegian and English.
This code (after the usort):
Code: Select all
foreach($browser_langs as $browser_lang)
{
$language = strtolower(trim($browser_lang[0]));
if(strlen($language) > 2) $language = substr($language, 0, 2);
if(in_array($language, array_keys($t_hls['parent']))) return $t_hls['parent']["$language"];
}
return DEFAULT_LANG;
first grab the first lang in the array (after the usort), and if usort is present then it wrongly
uses "en" in the first loop.
Since I have both English and Norwegian pages defined in my site then the second if statement in the foreach above
will be true in first loop and therefore it will WRONGLY return en_US.
This is quite easy to test:
E.g. in IE7, I have set Language preference list to show:
[no]
[en-US]
Then I delete all cookies for my localhost.
Then I replace the foreach loop above with this:
Code: Select all
foreach($browser_langs as $browser_lang)
{
$language = strtolower(trim($browser_lang[0]));
if(strlen($language) > 2) $language = substr($language, 0, 2);
if(in_array($language, array_keys($t_hls['parent']))) {echo "retlang='".$t_hls['parent']["$language"]."'"; return $t_hls['parent']["$language"];}
}
Have just put in an echo before the return statement in the second if to output what is returned.
Then save the script.
Then I enter
localhost/cmsmadesimple
in the address field in IE7 and it WRONGLY show my english version of the site and it display
that it return this value in the foreach loop above:
retlang='en_US'
The reason for that is as I have stated before:
the usort makes the en first priority (first in the $browser_langs array) which is not my browser setting at all).
Now, if I delete the cookies again and comment out the usort line in the function.mle.php and save the script:
Then I enter
localhost/cmsmadesimple
in the address field in IE7 and it CORRECTLY return my Norwegian pages for the site.
then the echo in the foreach loop returns this:
retlang='no_NO'
Now if you do not see that the usort line causes a BUG, then I give up trying to explain it to you and just hope someone else
in your team can see this, test it and get it fixed for future versions/users.....
It is a truly annoying bug.
That said, the usort line might not result in a bug for everyone, since it depends on what languages are defined
in the browser and the natural sort order of those languages (as is in the browser_langs array after usage of the usort) compared to the priority you have given to each language.
So in my case the usort causes a BUG!
But the question here should be:
What is the meaning of the usort line.... what is it ment to do? I belive it should never have been there.
Just my 1 cent.
Now I hope you see my point here and that you take this further to the developers.....
I feel I have used to much time allready on this bug.
I sat up most of the previous night trying to figure out what the h*** I was doing wrong since the site would not
honor my languages as set in my browser.
Best regards