Announcement

Symphony's issue tracker has been moved to Github.

Issues are displayed here for reference only and cannot be created or edited.

Browse

Closed#619: Author language setting works for frontend as well

Symphony's language management is capable of translating event and event filter XML messages, which is very cool. But...

Let's assume that you build a German website. Of course the frontend should always be German. You will set the (default) System Language to German, and voilà, you can even render your events' success and error messages directly in the website's frontend (assumed that there is a translation available, of course).

If, however, an author sets his language to English (because he is used to work in an English backend), all the frontend event messages will be English again. This will almost inevitably lead to a terrible mixture of German and English snippets in the website's frontend.

Why is this done at all?

I suggest that the frontend should always honour the System Language setting. The author's setting should override the System Language setting for the backend exclusively.

(If you are building multi-lingual websites, you will probably need to build an "event message translation layer" in XSLT anyway. So I don't see any additional problems with my suggestion.)

Well the messages on the Frontend will only be English for that Author, while logged in, it won't just change the Frontend to English for all.

I imagine this is a pretty difficult one to fix as the translation function is fairly simple. I suppose it could check if it's being called in the Frontend/Administration context and translate based off that, but it may produce some unpredictable results with some of the more complex extensions.

A fix should be quite simple. Only execute this line of code in backend context: https://github.com/symphonycms/symphony-2/blob/master/symphony/lib/core/class.symphony.php#L427

Ah, and maybe a note about the event messages:

The content of these messages is often quite obscure - it not always precise, it doesn't make sense in all contexts. Even without a translation they could not always be used for output directly. So I always thought that the messages should give me - as the developer - a clue what's going on, but that I have to create my own messages on the front-end using the event type. So, in my opinion, it would be great to have distinct error codes that can be match via xPath (like 200 or 404 for server responses). Something like members1, members2 etc.

@Nils Could you submit a pull request for this? I figure you are in the best position to test this.

In regards to the idea of distinct error codes, this is something I have brought up before with the idea of having a Knowledge Base. It's a fairly significant feature though, so probably more S3ish I would imagine.

I haven't found the time to prepare a pull request but Michael confirmed that this is working as expected:

public function isLoggedIn(){

    // Ensures that we're in the real world.. Also reduces three queries from database
    // We must return true otherwise exceptions are not shown
    if (is_null(self::$_instance)) return true;

    if ($this->Author){
        return true;
    }
    else{

        $username = self::$Database->cleanValue($this->Cookie->get('username'));
        $password = self::$Database->cleanValue($this->Cookie->get('pass'));

        if(strlen(trim($username)) > 0 && strlen(trim($password)) > 0){

            $id = self::$Database->fetchVar('id', 0, "SELECT `id` FROM `sym_authors` WHERE `username` = '$username' AND `password` = '$password' LIMIT 1");

            if($id){
                self::$Database->update(array('last_seen' => DateTimeObj::get('Y-m-d H:i:s')), 'sym_authors', " `id` = '$id'");
                $this->Author = AuthorManager::fetchByID($id);

                // Only set custom author language in the backend
                if(class_exists('Administration')) {
                    Lang::set($this->Author->get('language'));
                }

                return true;
            }
        }

        $this->Cookie->expire();
        return false;
    }
}

This is the important part:

// Only set custom author language in the backend
if(class_exists('Administration')) {
    Lang::set($this->Author->get('language'));
}

I sent a pull request.

Merged, thanks.

This issue is closed.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details