Possible bug found in script regarding Browser Language detection

This is a FORK of the CMS Made Simple project and is not oficially supported in any way by the CMS Made Simple development team.
Locked
bongobongo
Forum Members
Forum Members
Posts: 33
Joined: Thu Dec 11, 2008 11:41 pm

Possible bug found in script regarding Browser Language detection

Post by bongobongo »

Hi.

Have installed cms-mle

And found this:

In function.mle.php you have this code (in function language_user_setting()  ):

usort($browser_langs, "language_accept_order");

If I comment out that code it work as it should and honor my language settings in the browser:

I did a quick test doing this:

Code:
echo "Before: ";
print_r($browser_langs);

usort($browser_langs, "language_accept_order");

echo "After: ";
print_r($browser_langs);


And it looks to me that that usort makes it all fail:
Before usort it showed
no
en

in that order.
just as it is in my browser.

after it was
en
no

I do not see any reason to alter the order of the languages entered by the client in the browser and then use that
altered order to define which lang to use??

Looks like that is a bug?

If not a bug, then what is the reason for using usort here?

I originally posted my findings in this thread:
http://forum.cmsmadesimple.org/index.ph ... 700.0.html

But looks like it never was any real interest in it.

Anyway.... Now, finally and after one nights work my multilingual cmsmadesimple site finally detects and uses the
languages as set in client browser.

Before I commented out the usort line mentioned above, it DID not work as it should.

Regards
Last edited by bongobongo on Fri Dec 12, 2008 8:40 pm, edited 1 time in total.
alby

Re: Possible bug found in script regarding Browser Language detection

Post by alby »

bongobongo wrote: Have installed cms-mle
Move because this is relative to MLE version and not CMSMS original version (history).
However I answer to original topic

Alby
bongobongo
Forum Members
Forum Members
Posts: 33
Joined: Thu Dec 11, 2008 11:41 pm

Re: Possible bug found in script regarding Browser Language detection

Post by bongobongo »

Okay....

In function.mle.php, if you make some changes before and after usort line (in function language_user_setting()  ) to this:

Code: Select all

echo '<hr>Before:<br />';
foreach($browser_langs as $lang)
	echo $lang[0] .'-'. $lang[1].'<br />'; 
 
 	usort($browser_langs, "language_accept_order");

echo '<hr>After:<br />';
foreach($browser_langs as $lang)
	echo $lang[0] .'-'. $lang[1].'<br />'; 

Then I tested this in different browsers, making sure to delete any cookies for the site before the test.

*********************************************
I get this output in IE7:
*********************************************

Before:
no-1
en--1

After:
en--1
no-1

Which gives wrong result and wrong language is displayed.

*******************************
Now lets try IE6
*******************************

Before:
no-1
en--1

After:
en--1
no-1

Which gives wrong result and wrong language is displayed.

*******************************
Now lets try Chrome
*******************************

Before:
no-1
en--1

After:
en--1
no-1

Which gives wrong result and wrong language is displayed.


*******************************
Now lets see what happens in FF:
*******************************

Before:
no-1
en-us-0.5

After:
no-1
en-us-0.5

Which gives correct language....

*******************************
Now lets see what happens in OP:
*******************************

Before:
no-1
en-0.9

After:
no-1
en-0.9

Which gives correct language.....


***********
Conclusion
***********

It fails in: IE6, IE7 and Chrome.
It works in: Firefox and Opera.

At least using the languages I have set up.
I do belive this will fail for other's as well, but it depends on browser used as well as languages defined, and which order.

So IMHO, it is buggy with the usort line.

And... I do belive most people when they alter their Language Preferences do not think much about the q factor.
They enter a few languages in the preference list, and order them as they want.
Why not honor the order of the languages as the client browser (user) has it set?
Why sort this based on the q factor? Especially when it, for some, gives wrong result?

If you do not want to completely remove the usort line then why not eventually not use it by default, and optionally let
the admin activate it if he want. As it is now it is counterintuitive.

Best regards
Last edited by bongobongo on Sat Dec 13, 2008 9:50 am, edited 1 time in total.
alby

Re: Possible bug found in script regarding Browser Language detection

Post by alby »

TOPIC CLOSE for double posts.
Following original topic here.

Alby
Locked

Return to “[locked] CMSMS MLE fork”