Title: [Plugin: Polylang] Android language detection not done correctly
Last modified: August 20, 2016

---

# [Plugin: Polylang] Android language detection not done correctly

 *  [nalply](https://wordpress.org/support/users/nalply/)
 * (@nalply)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-polylang-android-language-detection-not-done-correctly/)
 * 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://wordpress.org/extend/plugins/polylang/](http://wordpress.org/extend/plugins/polylang/)

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

 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-polylang-android-language-detection-not-done-correctly/#post-2947653)
 * 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](https://wordpress.org/support/users/nalply/)
 * (@nalply)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-polylang-android-language-detection-not-done-correctly/#post-2947660)
 * Ah, I understand. arsort() does not do a stable sort:
 * [https://bugs.php.net/bug.php?id=53553](https://bugs.php.net/bug.php?id=53553)–
   has been closed as bogus.
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-polylang-android-language-detection-not-done-correctly/#post-2947759)
 * 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.

 * ![](https://ps.w.org/polylang/assets/icon-256x256.png?rev=3433336)
 * [Polylang](https://wordpress.org/plugins/polylang/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/polylang/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/polylang/)
 * [Active Topics](https://wordpress.org/support/plugin/polylang/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/polylang/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/polylang/reviews/)

## Tags

 * [android](https://wordpress.org/support/topic-tag/android/)

 * 3 replies
 * 2 participants
 * Last reply from: [Chouby](https://wordpress.org/support/users/chouby/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-polylang-android-language-detection-not-done-correctly/#post-2947759)
 * Status: not resolved