1

I am trying to implement a multilanguage site.

I have a hook handler for the hook sessions_start that is supposed to set the language for a page. Here are the lines of code from the hook to change the language that I have tried.

$this->EE->config->_global_vars['language'] = 'xxxxx';

$this->EE->config->_global_vars['default_language'] = 'xxxxx';

$this->user_lang = "xxxxx";

But none of them worked.

Any idea how to change the language in a hook?

P.S. Tried this

public function do_sessions_start($session_object)
{
 ....
 $session_object->userdata['language'] = "xxxxx";
}

But it seems it only works if the user is logged out. If logged in, the preference in the localization settings seems to overwrite.

We want to overwrite that.

1 Answer 1

1

The way I read the documentation on session hooks, what you set in sessions_start gets overridden by the logged in users settings.

Here is what the documentation says exactly: "Reset Session class variables, modify default/guest settings, take over whole session check, etc."

From what you're saying, I think you need your code on the sessions_end hook. Doc: "Modify the user’s session/member data, also allows for additional session or login methods (ex: log in to other system)."

Putting it on sessions_end, you will be able to overwrite the language variable, whether it's set from the logged in session or its the default value.

Link to documentation: http://ellislab.com/expressionengine/user-guide/development/extension_hooks/global/session/index.html

1
  • Following up. Did this resolve your issue, or did you find another way around it? Commented Sep 6, 2013 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.