We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

EE2 Can I change the session language from php from a tempate?

Development and Programming

FaithX's avatar
FaithX
120 posts
13 years ago
FaithX's avatar FaithX

I would like to change the session’s language from PHP. I need to change the language for visitors only.

Sorry for posting EE2 question here, but only my client has EE2 license.

       
Kevin Smith's avatar
Kevin Smith
4,784 posts
13 years ago
Kevin Smith's avatar Kevin Smith

Hi FaithX,

I’m not sure I understand the question. Could you give me a bit more detail about what you’re trying to achieve?

       
unicornesk's avatar
unicornesk
2 posts
13 years ago
unicornesk's avatar unicornesk

Hi Kevin!

I have a multilanguage site, all was done by myself. I am not using any extension or plugin. Visitors came to the site and read pages. They are not members, just unregistered visitors. All should be ok, but I need to show some system user messages and email templates. They came in the default language of the site for visitors. But I they visitors have unique sessions with unique settings. I ask if I can switch the current visitor’s language, his session language to show him correct messages? I did managed this now with messages, where is everything shown in 3 languages at a time. I had changed the default language files like this: value=”en<br />sk<br />de” But this looks not too good. As my template structure begins with language code like /en/ in segment_1, I should change the current language by the proper template. Is it possible to do it from a template? From PHP?

Thanks in advance! FaithX

       
Kevin Smith's avatar
Kevin Smith
4,784 posts
13 years ago
Kevin Smith's avatar Kevin Smith

There’s not a way to change the language of a logged-out visitor on the site. Have you considered using something like Multi Language Module? It fits with your decision to include the language in the URL structure of the site.

       
FaithX's avatar
FaithX
120 posts
13 years ago
FaithX's avatar FaithX

If there’s no way, how do this addon manage this? I think anything can be done, just we have to be familiar with the system. Has the session separate language settings? Or can I force the system massage’s language somehow?

By the way, I plan to write a review about EE2. I have worked with EE1 for many years. This was my first project with EE2, and I do not really plan any new with this. It was so horrible, so backward step from EE. All of the things I needed were more more complicated like in EE1. Almoust for every bit of development an Addon is required. The system itself has so many limitations, what makes it useless without addons. Even the new Control Panel is painfull. It’s nice, but not usefull. I was wold by some of our EE developer friends, the EE2 is worse then EE1. And now I can confirm this!

       
Kevin Smith's avatar
Kevin Smith
4,784 posts
13 years ago
Kevin Smith's avatar Kevin Smith

What I meant was that there’s no way to change the system’s default language settings for visitors for each individual visitor. It is what it is. EE knows that visitors should expect to view the site in a certain language. Logged-in users can choose language settings, but it’s not possible (natively) for a visitor to change that preference. The add-on that I pointed to tries to accomplish the same thing in a different way.

I hate to hear that you’ve not had a great experience with EE 2. We’re glad to see all the amazing sites people have launched with it, and we’re happy to work on making it better every day.

       
unicornesk's avatar
unicornesk
2 posts
13 years ago
unicornesk's avatar unicornesk

Sesssion is session, it’s unique. What if I change the Site’s default language for that short period? Is it possible to change that language from php? I did tried these:

//$this->prfx = $this->EE->db->dbprefix; //$this->EE->config->_global_vars[‘language’] = “Slovak”; //$this->EE->config->_global_vars[‘language_code’] = “sk” //$this->EE->config->_global_vars[‘user_language’] = “sk”; //$this->EE->session->userdata[‘language’] = “sk”;

I can found out that this value is stored in the database in a hashed format. I can disassembly this, but it would be easier if I get some help here.

I started with php In 1997, but I moved to C# in 2001, we are using frameworks like XAF from DevExpress for enterprise applications. You should try it sometime, that’s like a different galaxy, so so perfectly imagined and implemented managing very complex scenarios. The only drawback is the windows platform…

       
FaithX's avatar
FaithX
120 posts
13 years ago
FaithX's avatar FaithX

Sorry for changing the accounts!

I understand that those addons get the languages from the URL segments for example, but I do not know how they for the language of the system messages and email templates. Is there a hook or anything for this, I should create my own plugin for that.

       
Kevin Smith's avatar
Kevin Smith
4,784 posts
13 years ago
Kevin Smith's avatar Kevin Smith

I think they’re not using the system default at all, but using entirely their own methods for determining system language. I can’t really help with custom development here, but I’d be glad to move this thread over to the Development & Programming forum so you could ask other developers there if they have any solutions for you. Would you like me to do that?

       
FaithX's avatar
FaithX
120 posts
13 years ago
FaithX's avatar FaithX

Yes, please. Let’s take a try.

       
Kevin Smith's avatar
Kevin Smith
4,784 posts
13 years ago
Kevin Smith's avatar Kevin Smith

Sure thing!

       
FaithX's avatar
FaithX
120 posts
13 years ago
FaithX's avatar FaithX

Thanks!

       
joanmcapera's avatar
joanmcapera
3 posts
13 years ago
joanmcapera's avatar joanmcapera

Hi,

Im facing almost the same problem. I’m developing a multilanguage site in the usual way, with additional folders with index.php in each to configure some global variables and i was wondering if i could change some variable in the index.php file to force the system messages (login, error in registration, etc) to be in certain languages.

Should i lose my hope?

       
FaithX's avatar
FaithX
120 posts
13 years ago
FaithX's avatar FaithX

I believe that we can access that variable or class property or even the setting in the database, but actually I am on holiday, when I return I plan to figure this out. It looks that Ellis Lab do not want to allow this, but it should be possible. My experience is that in EE2 you can make only 30% of what I have done in EE1 easily, for everything a 3rd party addon is required. Which is a same. The EE2 itself is enough only for bare primitive sites, nothing usefull. I should want to see a site which is built without any addon or plugin only with the core EE2.

Returning to our issue. I know that in the states they are don’t care of the rest of the world, so multilanguage issue is our pain. But I believe many of us is confronting with the same issue, maybe there’s someone who did managed this already…

       
joanmcapera's avatar
joanmcapera
3 posts
13 years ago
joanmcapera's avatar joanmcapera

After some research i think i found something that at least makes the job:

1.- I add the languages to expression engine installation in the usual way.

2.- I add a session variable in the index.php. My site is like this:

/index.php /es/index.php

In the /es/index.php file i add this after my $assign_to_config vars:

$_SESSION['language'] = 'spanish';

3.- In /system/expressionengine/core/EE_Lang.php i add this in line 46:

if(isset($_SESSION['language'])) $EE->session->userdata['language'] = $_SESSION['language'];

Probably i broke something, but error messages on registration are localized now. More testing tomorrow. EDITED: I added a conditional to check if i set the variable in the index or not. Other workaround is add the variable in the /index.php with the default language.

About the plugins thing, can’t tell. This is my 1st site with a CMS so i don’t have any previous experience. I chose EE because i did a couple of sites with CI and i liked it, so I thought it was the natural route. Frankly, I found myself researching and using a lot of pluggins to get the things done, but as far i know, this happens with all CMS. Good thing is lot of pluggins are free, though i had to do litle modifications in some.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.