Page 2 of 4

Re: Language detection?

Posted: Fri Dec 12, 2008 1:32 pm
by alby
bongobongo wrote: Should not be much left to delete :)

Please re-read my previous post?
but maybe you must close browser because (I don't know the behaviour of UE) last cookie is in memory also

Alby

Re: Language detection?

Posted: Fri Dec 12, 2008 1:48 pm
by bongobongo
Something is strange:

Okay, I have IE7 with only [no] in the language preference list.

I enter:
http://localhost/cmsmadesimple/

and the site show up in Norwegian pages which is correct.

Then I add [en-US] to the  language preference list.
It is placed automatically after [no] in the list after I add it.

Then I enter:
http://localhost/cmsmadesimple/

And now the  site show up in English pages which is NOT correct.

And I belive I should not have to clear anything after adding the second language, since [no] was first priority in first place.

If I now remove the [en-US] again and clear anything (cookies, cache etc...) then
then Norwegian pages show up again as it should.

Any comments on this?

Re: Language detection?

Posted: Fri Dec 12, 2008 2:05 pm
by alby
bongobongo wrote: Any comments on this?
Order in your config_lang.php is the primary source of starting language
browser languages order (for quality) is the primary source of starting language
If your default language is NO put no before EN in yur config_lang.php

Alby

Re: Language detection?

Posted: Fri Dec 12, 2008 2:08 pm
by bongobongo
I had allready done that!

Any other suggestions?

Re: Language detection?

Posted: Fri Dec 12, 2008 2:27 pm
by alby
Finally:

Browser languages order (for quality) is the primary source of starting language
for every language (in this order) there is a check if exist this parent language in config_lang (match with block or parent), if exist then this is the current_language

If after all languages no language is found in config_lang then return DEFAULT_LANG

Alby

Re: Language detection?

Posted: Fri Dec 12, 2008 2:34 pm
by bongobongo
Note:

The problem I describe does not happen for Firefox.

But I have exactly same problem in IE7 and latest release of Chrome as described earlier.

I read what you posted in your last post, but does not allways work so.....

no_NO is my default language and is listed first in the array in config_lang.php
en_US is listed second in my array in config_lang.php

Looks to me the rules you say will be followed... are not happening.... at least not for me, in the two browsers
and in relation to my examples:

Why that happen I do not know???

Re: Language detection?

Posted: Fri Dec 12, 2008 3:13 pm
by bongobongo
This might have something to do with it:

in the file include.php this block of gode is not fired:

if(empty($force_mle_default)) $hl = language_user_setting($hls);
  else $hl = DEFAULT_LANG;

Could you please clearify if that is how it should be?

Sounds a bit strange to me though

Re: Language detection?

Posted: Fri Dec 12, 2008 3:19 pm
by alby
bongobongo wrote: in the file include.php this block of gode is not fired:

if(empty($force_mle_default)) $hl = language_user_setting($hls);
   else $hl = DEFAULT_LANG;
if $force_mle_default is empty or not set, current lang $hl take return value of language_user_setting function in mle/function.mle.php

Alby

Re: Language detection?

Posted: Fri Dec 12, 2008 4:50 pm
by bongobongo
What I was saying was that that particular block of code is never fired on my site.

That is: The else { } block with that code is not fired.

In SiteAdmin GlobalSettings I have unchecked "Force initial DEFAULT_LANG"
but that does not matter much if that block of code is never fired ... the whole {} else block which contains
all of this code:

Code: Select all

else
  {
     // bolle
   	
   if(empty($force_mle_default)) $hl = language_user_setting($hls);
   else $hl = DEFAULT_LANG;

   setcookie('mle', $hl, time()+86400, $cookie_path, $cookie_domain, $cookie_secure);
  }

and therefore the function language_user_setting is never fired either.

I tried to put exit(); where "// bolle" is now, and the pages where still  working....
meaning that that else did never fire.....

So would be nice if you could explain why it is like that?

Re: Language detection?

Posted: Fri Dec 12, 2008 4:59 pm
by bongobongo
I know see why:

That block of code was only run if the cookie did not exist .... bahhh

But now I can maybe find out why it is as it is :)

Re: Language detection?

Posted: Fri Dec 12, 2008 5:10 pm
by bongobongo
Done some more testing 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:

I did a quick test doing this:

Code: Select all

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

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?????

Is that a bug?

Regards

Re: Language detection?

Posted: Fri Dec 12, 2008 8:00 pm
by alby
bongobongo wrote: Is that a bug?
I am sorry, but I do not have this behavior ....
check your lang order here

Alby

Re: Language detection?

Posted: Fri Dec 12, 2008 8:20 pm
by bongobongo
With all respect Alby:

Look like you have not read my latest post very carefully.

Things where not working at it should.

Then I say I commented out a line in one of your core php files..... and then it work as it should.

So, a possible bug found!

And you are not even interested in looking into it.... bahhh

One more question: Are you one of the developers for cmsmadesimple or not?

Regards

Re: Language detection?

Posted: Fri Dec 12, 2008 9:11 pm
by alby
bongobongo wrote: With all respect Alby:
alby wrote: I am sorry, but I do not have this behavior ....
With all respect, I try 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 />'; 
and I have NOT your behavior....
same results (FF & IE7) and same result VS Accept-Language site test
if someone can confirm ..... if not it's not bug for me
if you want you can submit a bug request also to php site for them function (same of mine):
http://www.php.net/source.php?url=/incl ... hooser.inc

bongobongo wrote: One more question: Are you one of the developers for cmsmadesimple or not?
yes and admin project for MLE version
regards

Alby

Re: Language detection?

Posted: Fri Dec 12, 2008 10:28 pm
by bongobongo
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