Support » Plugin: Polylang » browser language according is not working, $_COOKIE[pll_language] not working

  • Resolved redyyu

    (@redyyu)


    Problem is, when I set URL modifications with “directory” type,
    1. language according to the browser is not working, and
    2. Cookie: Array ( [pll_language] => en is never change. even I click the language switcher, the web page is correct language but the cookie still not change.

    but if only I changed URL modifications to “The language is set from content. Posts, pages, categories and tags urls are not modified.” everything just fine.

    I am using Firefox and Chrome on Mac, both first language is not set to english.
    and my polylang is update from 1.2.1? I am not sure, last update Time is some day in Oct 2013.

    I tired more than 10 hour to try fix it. but doesn’t end well……..

    Some one can help me?
    ———————————
    There is my settings below.

    WordPress is 3.7.1

    Permalink Settings:
    Post name - http://www.djiplus.com/sample-post/

    Polylang Settings:
    checked When the front page is visited, set the language according to the browser preference

    URL modifications –
    The language is set from the directory name in pretty permalinks. Example: http://www.djiplus.com/en/my-post/

    Remove /language/ in pretty permalinks. Example: http://www.djiplus.com/en/

    Hide URL language information for default language

    http://wordpress.org/plugins/polylang/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter redyyu

    (@redyyu)

    There is sample url for test:
    http://www.djiplus.com

    try use firefox or chrome and set default language is not english.
    the problem come up.

    “set the language according to the browser preference”
    is not working.

    Plugin Author Chouby

    (@chouby)

    Could you please update Polylang to the latest version?
    That’s a known bug of 1.2 & 1.2.1
    http://wordpress.org/plugins/polylang/changelog/

    You will have to delete your cookie for the bug correction to be efficient.

    Thread Starter redyyu

    (@redyyu)

    my polylang version is 1.2.4, just update yesterday.
    yes I did clear my cache/cookie every time I test it.
    I did test in most newly firefox(set zh_CN first ) safari chrome(set zh_CN first ) on MacOS 10.9 and IE9/Chrome on windows7(Chinese version). every time I clear cache/cookie and restart the browser.
    also my friend did test it on his Mac and remote windows 2003.

    One thing I forget mention, I did change one second language’s slug to custom letter
    “zh” change to “cn”, my url will looks like http://www.domain.com/cn/……
    for english is just http://www.domain.com.

    When URL modifications to “The language is set from content. Posts, pages, categories and tags urls are not modified.” everything is fine.

    the problem only happened When
    “The language is set from the directory name in pretty permalinks. Example: http://www.domain.com/en/my-post/”
    and
    “Hide URL language information for default language” checked.
    which mean is “http://www.domain.com/en/” is should not be display in any time.

    I did try:

    If I “Hide URL language information for default language” un-checked.
    It’s also no problem at all.clearly url is /en or /cn by url.

    If I Choose URL modifications to “The language is set from content. Posts, pages, categories and tags urls are not modified.” also ok.
    but whatever the language is en_US or zh_CN. home page url is always looks like http://www.domain.com/. no /cn anymore.
    The contents of language is correct language version, but the url is no /en or /cn anymore. I won’t do that, because the website is running half year ago.

    try this link: http://www.djiplus.com/cn
    try click some link on the navbar(top of the page).

    Please help.
    Thank you very much.

    Plugin Author Chouby

    (@chouby)

    Did you try with twenty twelve and with all plugins deactivated except Polylang?

    Thread Starter redyyu

    (@redyyu)

    Yes, I did try with clear wordpress today.

    MacOS Chrome is fine.
    Firefox still not working, (did setting to zh-CN).

    Windows 7 IE9 Chrome is fine, firefox not working too. (native Chinese version of firefox).

    you can try
    http://dev.tinforce.com

    I print_r the language and cookie top of the page.

    Plugin Author Chouby

    (@chouby)

    Could you put a language switcher (either as a widget or in menus) in your test site? otherwise it is impossible to test.

    Thread Starter redyyu

    (@redyyu)

    http://dev.tinforce.com

    I language swather is on the top now.

    Plugin Author Chouby

    (@chouby)

    For me, there is no problem with this installation. your cookies are correct (I read them with the web developper extension of Firefox).

    I don’t know how you wrote your code to display the cookies but probably it reads it before Polylang sets it. So you have the correct information on the second visited page in a language and not on the first one.

    Thread Starter redyyu

    (@redyyu)

    This problem is only happen when first time enter the website.
    “set the language according to the browser preference”

    In Firefox, While first time enter the website (no cookie, and firefox set default is zh-CN), the webpage must be according to the Chinese page. but is not.

    after you click the language switcher, the problem is gone, because firefox is already saved cookie.

    Please try:
    1. open blank page on firefox
    2. Clear cookie and history
    3. enter http://dev.tinforce.com
    4. see the url and contents result.

    Correct:
    The url must automatic to http://dev.tinforce.com/cn
    and website has Chinese contents.
    (This is must to be. right? )

    Incorrect:
    The url must automatic to http://dev.tinforce.com/
    and website is all english.
    (This is what happen now.)

    Thread Starter redyyu

    (@redyyu)

    Please also try Chrome, you will see the different.
    (only the first time enter the website, make sure there is no cookie at all).

    Plugin Author Chouby

    (@chouby)

    Sorry for being so long to understand 🙁

    Polylang first compares this code to the browser preferences. A match is found if the browser preference starts by the language code ‘cn’. In your case it can’t happen as this code does not exist.

    Then there is a second try to compare the locale (zh-CN) with the browser preferences. So it won’t work if only ‘zh’ is in browser preference but should work if there is ‘zh-CN’. The issue is that this comparison is case sensitive and:
    Chrome sends zh-CN
    while Firefox sends zh-cn 🙁

    So please try modifying the file frontend/choose-lang.php at line 115 from

    if (empty($pref_lang) && (0 === stripos($accept_lang, $language->slug) || $accept_lang == str_replace('_', '-', $language->locale)) )

    to

    if (empty($pref_lang) && (0 === stripos($accept_lang, $language->slug) || 0 === strcmp($accept_lang, str_replace('_', '-', $language->locale))) )

    Thread Starter redyyu

    (@redyyu)

    Thank you very much.

    Plugin Author Chouby

    (@chouby)

    Sorry, that should not work either. Please try

    if (empty($pref_lang) && (0 === stripos($accept_lang, $language->slug) || 0 == strcasecmp($accept_lang, str_replace('_', '-', $language->locale))) )

    Thread Starter redyyu

    (@redyyu)

    Thank you. looks work perfectly now….:)

    Plugin Author Chouby

    (@chouby)

    I will include this in v1.3

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘browser language according is not working, $_COOKIE[pll_language] not working’ is closed to new replies.