Alright, version 1.0.5 should now switch the search and profile pages. All you need to do is make sure your titles are named the same as the language packs. For example if you have a language in your extension like this:
_fr:French
Then you’ll want to have a language pack named ‘French’. Notice the capitals because case does matter. Luckily, I’ve found that you can rename the language pack to be any case you want.
1. Huh. Very interesting, so if I don’t include the prefix it will be added automatically? Or should I include exp_ and it will be changed to suit the installations needs?
The latter, exp_ is automatically replaced whatever the user’s prefix actually is, if their installation’s prefix differs.
Actually on cookies the prefix, domain, etc. are just added, not replaced. So your cookies just use a descriptive name, something that will not potentially clash with other cookies or addons. If you sent ‘mh_lang’ to the $FNS->set_cookie() method, it would create a cookie named ‘exp_mh_lang’, or ‘prefix_mh_lang’ if they have a different value set in that preference.
hi - just saw this thread by way of Jambor-ee…. good stuff! I have a two language site that i did with a friend using his custom PHP code, and so we didn’t use EE. Now it looks like I’ll be able to use your extension to migrate to EE. Yet another project to look forward to! PS On our present setup we have the ENG / IT option at the top of all our pages and one can switch to either language from whatever current page one is viewing. Does your extension work the same way? Cheers. and Many Thanks.
PS hope you and Cocoaholic can integrate your solutions as they sound like they extend the capabilities of yours….
Mark,
I don’t think your set_admin_language() function works, at least not for me. You are probably running into the same problem I ran into when I was trying to build a solid language switcher.
See this thread for details: http://ellislab.com/forums/viewthread/31742/.
Does it work for others? Maybe only in PHP 5?
Wondering out load: It would seem to me that this option of being able to switch languages on the fly is something that many folks would be glad to have and it would indeed help EE in attracting new customers because of this capability. Therefore, is it something that perhaps could be rolled into a forthcoming version of EE? Mark and others have done a super job and this could be the foundation on which EE can roll it into their production cycle? I am specifically referring to a Language Switch for page viewing and not the back-end admin areas, although that could be also incorporated. Just a thought….
@Cocoaholic, You are correct, the function will only work in PHP5. I’ll try to check out a workaround for PHP4, but I’m not sure what could be done without hacking the core files. I’ve also submitted a feature request through your linked thread to hopefully get a few more hooks into the template system.
@giovanni, I concur. this would be a nice feature.
Excellent extension Mark!
One little question: Is it possible to check which language is active? I have two languages Dutch and English and I only want to display the option which is currently not active. So if the language is Dutch, i want to have a link that says ‘English’ and vice versa.
I tried it with a {if} statement but i cant figure out which variable to use.
Anyone a suggestion?
The way it’s working now an {if /} statement won’t work. It’s kind of finicky that way because the XHTML is calculated before the template even begins parsing. I did it that way to simplify things, otherwise I’d need to bundle a plugin with the extension. That being said, there should be enough CSS hooks in there to style it so that the active language is hidden.
Robert,
For now you could use this PHP snippet, or something similar.
<?php
global $SESS;
if ( isset($SESS->cache['mh_field_list']['title_nl']) ) {
echo '<a href="http://domain.com/index.php/lang/default/">English</a>';
} else {
echo '<a href="http://domain.com/index.php/lang/_nl/">Nederlands</a>';
}
?>
Make sure you change the domain name name and correct the path. If your default language is Dutch you also need to change the code to this:
<?php
global $SESS;
if ( isset($SESS->cache['mh_field_list']['title_en']) ) {
echo '<a href="http://domain.com/index.php/lang/_en/">English</a>';
} else {
echo '<a href="http://domain.com/index.php/lang/default/">Nederlands</a>';
}
?>
I dare say you could probably even make your links relative, so you don’t have to alter them on every page
<?php
global $IN;
if ( isset($IN->global_vars['simple_language']) && $IN->global_vars['simple_language'] == '_en' ) {
echo '<a href="http://lang/_en/">English</a>';
} else {
echo '<a href="http://lang/default/">Nederlands</a>';
}
?>
I also switched the condition around to use one of the global variables the extension sets.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.