Multilingual plugin "forgets" default language

Found a bug? Tell us!!
User avatar
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Multilingual plugin "forgets" default language

Post by wesley » Mon Apr 18, 2016 3:56 am

I'm currently using the latest (2.22) version of serendipity_event_multilingual on s9y 2.0.3.
My blog is at http://tool-box.info , as noted in my signature.

For a multilingual entry, a set of links appears at its bottom to allow the visitor to choose the language of the entry like this:

Select language: Korean, English

Since my blog's primary language is English (Admin > Configuration > General Settings > Language), the Korean entry has the language code of "ko", while the English version is the "default" one. This can be verified by looking at the URLs of the link.

When the visitor chooses "Korean" as the language, however, the links appear like so:

Select language: Korean, Korean

The URLs remain the same, but the "default" entry is also labeled as Korean. Apparently, the plugin "forgets" that the blog's default language is English.

Interestingly, this does not happen as long as I'm logged into the administration page.

So maybe there's a bug where the plugin isn't properly detecting the blog's default language somehow when a non-default language is chosen via the language selector?

I haven't seen this problem a couple of years ago, so perhaps something happened in between. Does anyone have an idea what might be happening?
I make s9y plugins, too.
My s9y blog depends on them. :)

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Multilingual plugin "forgets" default language

Post by Timbalu » Mon Apr 18, 2016 11:06 am

The latest version is 2.24 (event) & 1.13 (sidebar)!

http://tool-box.info/blog/index.php?arc ... fault.html
It always stays "Korean, English", when you change the lang via these entries footer links.
And Yes, it changes to "Korean, Korean" when you change to Korean lang via the selectbar lang switcher. Being logged-in this does not happen.
The footer links change the used lang for the browsers session only, the select bars lang switch as a remembered cookie, which relies on your backend set languages. The PP lang is the more valid lang.

In my local tests, which I have available since I modified the Plugin in the last year, this is the same, while I have English set in Configuration and German set in PP. See https://github.com/s9y/Serendipity/issues/361

So I assume it is while you have a difference between the (Admin > Configuration > General Settings > Language) and your "Personal Preferences" language. (This, while Cookie is always "one step behind" and you then have 3 options set: config, pp and selected lang. And btw, it overrules the backend language, which it shouldn't do, IMHO.)
For this "feature" they need to be off the same language, I think! Try it out, to see if that avoids this behaviour.

Please stop your dancing badger. I am not really willing to see this every time I have to read and answer your posts. Please! :)
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian

User avatar
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Re: Multilingual plugin "forgets" default language

Post by wesley » Mon Apr 18, 2016 11:39 am

I've deleted the avatar until a suitable replacement is found. :)

Both the "Personal" and "General" preferences have "English" as the default language. So this isn't that issue, I think.
I make s9y plugins, too.
My s9y blog depends on them. :)

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Multilingual plugin "forgets" default language

Post by Timbalu » Mon Apr 18, 2016 11:46 am

Thanks!
wesley wrote:Both the "Personal" and "General" preferences have "English" as the default language. So this isn't that issue, I think.
Did you start with a fresh cookie?

Please also check this http://board.s9y.org/viewtopic.php?f=4&t=19820
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian

User avatar
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Re: Multilingual plugin "forgets" default language

Post by wesley » Mon Apr 18, 2016 1:58 pm

I deleted cookies in a couple of browsers and gave them a try, but it did not help with the issue, sadly.

By the way, SPARTACUS on my blog didn't catch the existence of the version 2.24 of the plugin. I did a manual update, but it still doesn't solve the issue.

I tried using the original sidebar plugin for selecting the language instead of the one I included in the theme's navbar. Still the same.

As I remember it, I never changed the blog's default language, global or personal, from English, ever. So it seems there's no way the blog would even consider itself as having Korean as a default language from the settings. So configuration doesn't seem to be related to the cause of the problem.
I make s9y plugins, too.
My s9y blog depends on them. :)

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Multilingual plugin "forgets" default language

Post by Timbalu » Mon Apr 18, 2016 2:30 pm

It is related, IMHO, since the value you see in (Admin > Configuration > General Settings > Language) is not always the real value stored in the database. It may just show the value of your selected lang in PP or selected lang by frontend, chosen as admin. So you cannot trust it! (See Garvins explaination in the pasted thread.)

Well, the problem arises because of $serendipity['default_lang'] being a little idle.
I haven't yet found a good way to keep the other lang link for visitors only, without avoiding this idle $serendipity['default_lang'] behaviour and to check the db config set lang on each request, which seems a bad idea to do. I assume we would need an, as long as possible stored, default db config value lang procedure for frontend visitors, readable by everyone, even the ones using no cookies, etc.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Multilingual plugin "forgets" default language

Post by Timbalu » Mon Apr 18, 2016 2:40 pm

wesley wrote:By the way, SPARTACUS on my blog didn't catch the existence of the version 2.24 of the plugin. I did a manual update, but it still doesn't solve the issue.
Maybe you got an issue in the serendipity_pluginlist db table?
The fields version and upgrade_version could interfere.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian

User avatar
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Re: Multilingual plugin "forgets" default language

Post by wesley » Mon Apr 18, 2016 4:11 pm

Timbalu wrote:It is related, IMHO, since the value you see in (Admin > Configuration > General Settings > Language) is not always the real value stored in the database. It may just show the value of your selected lang in PP or selected lang by frontend, choosen as admin. So you cannot trust it! (See Garvins explaination in the pasted thread.)
Indeed, so just to make sure, I checked the DB under serendipity_config...

name / authorid / value
lang / 0 / en
lang / 1 / en

So I think it's safe to say the values being shown are real in this particular case. Unfortunately, both are seemingly ignored when a visitor just chooses "Korean" from the dropdown box.
Timbalu wrote:Well, the problem arises because of $serendipity['default_lang'] being a little idle.
I haven't yet found a good way to keep the other lang link for visitors only, without avoiding this idle $serendipity['default_lang'] behaviour and to check the db config set lang on each request, which seems a bad idea to do. I assume we would need an, as long as possible stored, default db config value lang procedure for frontend visitors, readable by everyone, even the ones using no cookies, etc.
Yeah, that sounds reasonable. Until it gets resolved definitely, would it be possible to make an option to just show it up as "Default", perhaps? Just a suggestion.
Timbalu wrote:Maybe you got an issue in the serendipity_pluginlist db table?
The fields version and upgrade_version could interfere.
I also checked the serendipity_pluginlist table. Both "version" and "upgrade_version" for the local copy of serendipity_event_multilingual shows up as 2.24 at the moment, so let's not dwell on that for the time being.
I make s9y plugins, too.
My s9y blog depends on them. :)

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Multilingual plugin "forgets" default language

Post by Timbalu » Mon Apr 18, 2016 4:44 pm

wesley wrote:Yeah, that sounds reasonable. Until it gets resolved definitely, would it be possible to make an option to just show it up as "Default", perhaps? Just a suggestion.
Adding options etc is easy ... though it is a table lookup too. I'd like to avoid this per each frontend request.
As I said, we would need a way to have this stored - best by the cores global $serendipity array.
I'd still like to have Garvin chime into this topic, since there also is this related "influence the backend lang" topic.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian

User avatar
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Re: Multilingual plugin "forgets" default language

Post by wesley » Tue Apr 19, 2016 3:46 am

On testing the multilingual plugin further, I've encountered yet another problem - "force full language switch" isn't working. This sounds like what ophian experienced here:

https://github.com/s9y/Serendipity/issues/361

For the moment, I've turned that option off to have the article translated only, which is working because the URL is formed like this (the brackets interfere with BBCode, so I'll post it as a code):

Code: Select all

http://tool-box.info/blog/index.php?archives/1976-Korean.html&serendipity[lang_selected]=ko
However, with the "force" option on, the URL adds "serendipity[user_language]=ko" and when that happens nothing changes - neither that blog's language or the article's language:

Code: Select all

http://tool-box.info/blog/index.php?archives/1976-Korean.html&serendipity[lang_selected]=ko&serendipity[user_language]=ko
This is strange because the dropdown box form sending user_language=ko via POST method is working just fine:

Code: Select all

<form id="language_chooser" action="http://tool-box.info/blog/" method="post">
    <div>
        <select name="user_language" onchange="document.getElementById('language_chooser').submit();">
            <option value="en" selected="selected">English</option>
            <option value="ko" >Korean</option>
        </select>
    </div>
</form>
But appending in URL doesn't work. This doesn't work either, that is:

Code: Select all

http://tool-box.info/blog/index.php?archives/1976-Korean.html&serendipity[user_language]=ko
I wonder if this issue is related to what we've been discussing? And does anyone have an idea on how to get this working again?
I make s9y plugins, too.
My s9y blog depends on them. :)

User avatar
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Re: Multilingual plugin "forgets" default language

Post by wesley » Tue Apr 19, 2016 8:55 am

Okay, this is very interesting.

As an experiment, I've replaced the code in plugin_event_multilingual with ophian's code from August 6, 2015 at https://github.com/s9y/Serendipity/issues/361 and observed the behaviour.

Specifically, this...

Code: Select all

if (!defined('IN_serendipity_admin')) {
    $resetlang = false;
    // GET is either a forced session or a single entry lang and we normally do not use it with cookies set, since they have preference
    if (serendipity_db_bool($this->get_config('langswitch')) && (!isset($_POST['user_language']) || !isset($_COOKIE['serendipityLanguage']))) {
        // check for REQUESTs being sent (imagine the user in a DE blog links an EN entry version and force option is set TRUE)
        // $_REQUEST was somehow disabled and not available, but used here and in serendipity_getSessionLanguage()
        $_REQUEST['user_language'] = $serendipity['GET']['user_language'];
        // normal fallback
        if (!isset($serendipity['GET']['lang_selected']) && !isset($_REQUEST['user_language'])) {
            if (!empty($_SESSION['serendipityLanguage'])) $this->showlang = $_SESSION['serendipityLanguage'];
        }
    } elseif (!isset($_COOKIE['serendipityLanguage'])) $resetlang = true; // force == false and we only want the translated article, nothing else being touched multilingual
}
...was replaced as this:

Code: Select all

if (!defined('IN_serendipity_admin')) {
    // check for REQUESTs being sent (imagine the user in a DE blog links an EN entry version and force option is set TRUE)
    // $_REQUEST was somehow disabled and not available, but used here and in serendipity_getSessionLanguage()
    $_REQUEST['user_language'] = $serendipity['GET']['user_language'];
    // normal fallback
    if (!isset($serendipity['GET']['lang_selected']) && !isset($_REQUEST['user_language'])) {
        if (!empty($_SESSION['serendipityLanguage'])) $this->showlang = $_SESSION['serendipityLanguage'];
    }
}
And this...

Code: Select all

if (!defined('IN_serendipity_admin')) {
    // case reset TRUE without POST cookies
    if ($resetlang && !isset($_COOKIE['serendipityLanguage'])) {
        $serendipity['lang'] = $this->showlang = $_SESSION['serendipityLanguage'] = $_SESSION['last_lang'] = $serendipity['default_lang']; // reset strictly to default global language
    }
    // case force langswitch to default, normally without POST cookies set, since they have preference
    if (serendipity_db_bool($this->get_config('langswitch')) && (!isset($_POST['user_language']) || !isset($_COOKIE['serendipityLanguage']))) {
        // a user has already set a forced language and now wants to return to the default language - doing such here after all, avoids a doubleclick need..
        if ($this->showlang == 'default' || $_SESSION['last_lang'] == 'default') {
            $serendipity['lang'] = $this->showlang = $_SESSION['serendipityLanguage'] = $_REQUEST['user_language'] = $serendipity['default_lang'];
            if ($_SESSION['last_lang'] == 'default') $_SESSION['last_lang'] = $serendipity['default_lang'];
        } // the entry is shown in default language as a fallback, when another language is chosen that has no entryproperties translation
    }
    // case repair cookie array
    if (isset($_COOKIE['serendipity']['serendipityLanguage'])) {
        $_COOKIE['serendipityLanguage'] = $_COOKIE['serendipity']['serendipityLanguage'];
        unset($_COOKIE['serendipity']);
    }
    // case POST set cookies mean, always check cookies to set current lang!
    if (isset($_COOKIE['serendipityLanguage'])) {
        // reset all langs strictly to default global hold COOKIE language
        $serendipity['lang'] = $this->showlang = $_SESSION['serendipityLanguage'] = $_SESSION['last_lang'] = $serendipity['default_lang'] = $_COOKIE['serendipity']['serendipityLanguage'] = $_COOKIE['serendipityLanguage'];
        $this->lang_display  = ''; // need this to always get the correct set lang and be the default in case of fallback and default
    }
    // case unforced language entry lang links
    if (isset($serendipity['GET']['lang_selected']) && !isset($serendipity['GET']['user_language'])) {
        $this->lang_display = $this->showlang = $serendipity['GET']['lang_selected'];
    }
    if ($serendipity['GET']['lang_selected'] == 'default' && !isset($serendipity['GET']['user_language'])) {
        $this->lang_display = ''; // sets entry lang to default
    }
}
...was replaced with this:

Code: Select all

if (!defined('IN_serendipity_admin')) {
    // a user has already set a forced language and now wants to return to the default language - doing such here, avoids a doublecklick need..
    if ($this->showlang == 'default' || $_SESSION['last_lang'] == 'default') {
        if (isset($_COOKIE['serendipityLanguage'])) $_COOKIE['serendipityLanguage'] = $serendipity['default_lang'];
        $this->showlang = $serendipity['default_lang'];
        $_SESSION['serendipityLanguage'] = $_REQUEST['user_language'] = $serendipity['default_lang'];
        if ($_SESSION['last_lang'] == 'default') $_SESSION['last_lang'] = $serendipity['default_lang'];
        $serendipity['lang'] = $serendipity['default_lang'];
    } // the entry is shown in default language as a fallback, when another language is chosen that has no entryproperties translation
}
The results:

- "Select language: Korean, English" actually shows up properly regardless of language selection.
- [user_language]=ko is ignored when used when English is used, but entry appears in Korean.
- [user_language]=default works when Korean is used, with both blog and entry appearing in English.

If the second one can be fully functional, then my troubles will be over.
I make s9y plugins, too.
My s9y blog depends on them. :)

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Multilingual plugin "forgets" default language

Post by Timbalu » Tue Apr 19, 2016 1:00 pm

I am not sure to which post of me you refer, which hasn't been touched already... I don't think it all has been solved already with the current code, but these 2.20 to 2.24 changes since last summer were the last state of my tests... including the still open question in #361.

This lang selection thing is a totally complicated thing. Since you have Cookies, Sessions, GET & POST vars, static properties, headers, global Serendipity vars, hooks, remembered or forced language options and all kind of different usage scenarious that interfere. You have frontend and backend only, back- and frontend being logged-in, all kind of author id 0 (default) and 1 (admin) and/or user languages, directed to or chosen by: select, link, blog, entries, default, multilingual modifier languages and or places. ETC. (I remember to have lastly come to the clue, to never change the language by link or selection in the frontend, being logged-in and/or using the same browsers session, since that boosts the possibilities and error cases.)

I have to admit, I always get slight dizzy trying to reconcile all these possibilities and to catch them logically step by step. It is also very hard to test, since you alway need a clean and untouched system (say: no cookies, sessions etc.)
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian

User avatar
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Re: Multilingual plugin "forgets" default language

Post by wesley » Wed Apr 20, 2016 3:19 am

I've done further tests and I have finally isolated the code that causes both the "Select language:" displaying as "Korean, Korean" and the "Force full language switch" not working at all in my blog. My hunch about these two being related seemed to have been correct.

Code: Select all

    // case POST set cookies mean, always check cookies to set current lang!
    if (isset($_COOKIE['serendipityLanguage'])) {
        // reset all langs strictly to default global hold COOKIE language
        $serendipity['lang'] = $this->showlang = $_SESSION['serendipityLanguage'] = $_SESSION['last_lang'] = $serendipity['default_lang'] = $_COOKIE['serendipity']['serendipityLanguage'] = $_COOKIE['serendipityLanguage'];
        $this->lang_display  = ''; // need this to always get the correct set lang and be the default in case of fallback and default
    }
When only this part is commented out, the behaviour is identical to what I saw with the temporarily replaced code, i.e. everything works properly again, mostly. Maybe that code resets things too aggressively? Until a better solution comes out, I would have to disable that portion in the code for the time being.
I make s9y plugins, too.
My s9y blog depends on them. :)

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Multilingual plugin "forgets" default language

Post by Timbalu » Wed Apr 20, 2016 10:57 am

Well done! Yes.
I sadly don't remember why I thought this to be a need though...
I'll rewrite this as soon we found out the other issues (archive and backend header).

Edit: I think I catched them all and just pushed 2.25. Available with Spartacus by tomorrow.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian

User avatar
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Re: Multilingual plugin "forgets" default language

Post by wesley » Wed Apr 20, 2016 2:03 pm

Timbalu wrote:I think I catched them all and just pushed 2.25. Available with Spartacus by tomorrow.
Thank you! I'm not in front of my server at the moment, so I'll take a look when it's on Spartacus and I can update it remotely.
I make s9y plugins, too.
My s9y blog depends on them. :)

Post Reply