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

Simple Translator (formerly known as Another Language Switcher)

Development and Programming

Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

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.

       
Derek Jones's avatar
Derek Jones
7,561 posts
18 years ago
Derek Jones's avatar Derek Jones
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.

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

I see. Thanks. Is this the same functionality for the Cookie Name, using $FNS->set_cookie()?

       
Derek Jones's avatar
Derek Jones
7,561 posts
18 years ago
Derek Jones's avatar Derek Jones

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.

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

I see, thanks for clearing that up.

       
giovanni's avatar
giovanni
203 posts
18 years ago
giovanni's avatar giovanni

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 Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

giovanni, it does work like your existing setup, i believe. and it also now integrates cocoaholic’s extension. you can read more about that in the first post to this thread.

       
Cocoaholic's avatar
Cocoaholic
445 posts
18 years ago
Cocoaholic's avatar Cocoaholic

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?

       
giovanni's avatar
giovanni
203 posts
18 years ago
giovanni's avatar giovanni

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….

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

@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.

       
Robert Eerhart's avatar
Robert Eerhart
57 posts
18 years ago
Robert Eerhart's avatar Robert Eerhart

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?

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

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.

       
Cocoaholic's avatar
Cocoaholic
445 posts
18 years ago
Cocoaholic's avatar Cocoaholic

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>';
}
?>
       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

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.

       
Cocoaholic's avatar
Cocoaholic
445 posts
18 years ago
Cocoaholic's avatar Cocoaholic

Even better! 😊

       
1 2 3 4 5 Last

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.