• My Android 4.0.4 sends the header

    HTTP_ACCEPT_LANGUAGE: de-CH, en-US

    this is changed to:

    $accept_langs = array(
      'de-CH' => 1,
      'en-US' => 1,
    )

    in the function core.php:get_preferred_language().

    Expected behaviour: Going to the german version.
    Real behaviour: Going to the english version.

    It seems that get_preferred_language() does not cope with identical q values and can lose the language order (first de-CH then en-US).

    http://ww.wp.xz.cn/extend/plugins/polylang/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Chouby

    (@chouby)

    I reproduce the bug. It comes from the output of the function arsort.

    [fr-FR] => 1
    [en-US] => 1
    [de-DE] => 0.8
    is sorted in:
    [fr-FR] => 1
    [en-US] => 1
    [de-DE] => 0.8
    which is OK

    [fr-FR] => 1
    [en-US] => 1
    is sorted in:
    [en-US] => 1
    [fr-FR] => 1
    which is not OK

    Don’t know yet how to solve this issue

    Thread Starter nalply

    (@nalply)

    Ah, I understand. arsort() does not do a stable sort:

    https://bugs.php.net/bug.php?id=53553 – has been closed as bogus.

    Plugin Author Chouby

    (@chouby)

    Could you try this ?
    In Polylang/includes/core.php, around line 125, replace:

    if (count($lang_parse[1])) {
    	// NOTE: array_combine => PHP5
    	$accept_langs = array_combine($lang_parse[1], $lang_parse[4]); // create a list like "en" => 0.8
    	// set default to 1 for any without q factor
    	foreach ($accept_langs as $accept_lang => $val) {
    		if ($val === '') $accept_langs[$accept_lang] = 1;
    	}
    	arsort($accept_langs, SORT_NUMERIC); // sort list based on value

    by:

    $k = $lang_parse[1];
    $v = $lang_parse[4];
    if ($n = count($k)) {
    	foreach ($v as $key => $val)
    		if ($val === '') $v[$key] = 1;
    	if ($n > 1) {
    		for ($i = 2; $i <= $n; $i++)
    			for ($j = 0; $j <= $n-2; $j++)
    				if ( $v[$j] < $v[$j + 1]) {
    					$temp = $v[$j];
    					$v[$j] = $v[$j + 1];
    					$v[$j + 1] = $temp;
    					$temp = $k[$j];
    					$k[$j] = $k[$j + 1];
    					$k[$j + 1] = $temp;
    				}
    	}
    	$accept_langs = array_combine($k,$v);

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘[Plugin: Polylang] Android language detection not done correctly’ is closed to new replies.