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.

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

  • Following up. Did this resolve your issue, or did you find another way around it? – Tim FitzGerald Sep 6 '13 at 14:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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