3 of 9
3
Simple Translator (formerly known as Another Language Switcher)
Posted: 09 May 2007 03:47 PM   [ Ignore ]   [ # 37 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  879
Joined  02-05-2002

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://expressionengine.com/forums/viewthread/31742/.

Does it work for others?
Maybe only in PHP 5?

 Signature 

Member of the EE Pro Network

Profile
 
 
Posted: 09 May 2007 04:07 PM   [ Ignore ]   [ # 38 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  303
Joined  09-30-2003

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

Profile
 
 
Posted: 09 May 2007 04:33 PM   [ Ignore ]   [ # 39 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

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

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 11 May 2007 05:12 AM   [ Ignore ]   [ # 40 ]  
Summer Student
Avatar
Total Posts:  29
Joined  10-17-2006

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?

 Signature 
Profile
 
 
Posted: 11 May 2007 05:21 AM   [ Ignore ]   [ # 41 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

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.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 11 May 2007 05:52 AM   [ Ignore ]   [ # 42 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  879
Joined  02-05-2002

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>';
}
?>

 Signature 

Member of the EE Pro Network

Profile
 
 
Posted: 11 May 2007 05:56 AM   [ Ignore ]   [ # 43 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

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="lang/_en/">English</a>';
} else {
    
echo '<a href="lang/default/">Nederlands</a>';
}
?>

I also switched the condition around to use one of the global variables the extension sets.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 11 May 2007 06:06 AM   [ Ignore ]   [ # 44 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  879
Joined  02-05-2002

Even better! smile

 Signature 

Member of the EE Pro Network

Profile
 
 
Posted: 11 May 2007 06:24 AM   [ Ignore ]   [ # 45 ]  
Summer Student
Avatar
Total Posts:  29
Joined  10-17-2006

Thanks guys… this helped me a lot!

At first it didn’t work, but the right code (for me) must be:

<?php
global $IN;
if ( isset(
$IN->global_vars['simple_language']) && $IN->global_vars['simple_language'] == 'English' ) {
    
echo '<a href="{path="site_index"}/lang/default/">Nederlands</a>';
} else {
    
echo '<a href="{path="site_index"}/lang/_en/">English</a>';
}
?>

I even can use {if simple_language == “Nederlands”} code {/if}

So i’m happy!

 Signature 
Profile
 
 
Posted: 11 May 2007 06:31 AM   [ Ignore ]   [ # 46 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

Well isn’t that sexy.  I’d use the EE conditional to keep it all in the family.  Anyway, I’m glad you got it figured out.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 11 May 2007 06:32 AM   [ Ignore ]   [ # 47 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  879
Joined  02-05-2002

Nice, I’d drop the PHP code and use this instead:

{if simple_language == "English"}
<a href="{path="site_index"}/lang/default/">Nederlands</a>
{if:else}
<a href="{path="site_index"}/lang/_en/">English</a>
{/if}

 Signature 

Member of the EE Pro Network

Profile
 
 
Posted: 11 May 2007 07:00 AM   [ Ignore ]   [ # 48 ]  
Summer Student
Avatar
Total Posts:  29
Joined  10-17-2006

Translation works like a clock!

Only the category names are still an issue.

 Signature 
Profile
 
 
Posted: 11 May 2007 08:42 AM   [ Ignore ]   [ # 49 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

Indeed.  Glad the rest of it’s working for you though.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 11 May 2007 10:05 AM   [ Ignore ]   [ # 50 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

Alright, I have it switching categories now.  It’s a hack, but I’m pretty pleased with it.  You can read about the implementation at the top of the thread, but as a teaser you only need to perform the following:

{exp:weblog:categories weblog="blog" category_group="{exp:translator:category_group="4"}"}&hellip;{/exp:weblog:categories}

If category group 4 were named ‘blog’ and there was another category group named ‘blog_ja’ it would switch blog to the suffixed version assuming a user is browsing in japanese.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 11 May 2007 10:08 AM   [ Ignore ]   [ # 51 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  303
Joined  09-30-2003

w00t! w00t!!

Profile
 
 
Posted: 11 May 2007 11:15 AM   [ Ignore ]   [ # 52 ]  
Summer Student
Avatar
Total Posts:  29
Joined  10-17-2006

Mark, this is working for me! Thanx for the fast solution

Super! Give this man a medal, please!

 Signature 
Profile
 
 
Posted: 12 May 2007 12:57 AM   [ Ignore ]   [ # 53 ]  
Lab Assistant
RankRank
Total Posts:  281
Joined  12-09-2006

Hi Mark,

I get a syntax error…

Error

The following tag has a syntax error
:

{exp:language:switcher}

Please correct the syntax in your template
.

My template is just this…

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<
head>
    <
meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <
title>Testing</title>        
</
head>
<
body>

{exp:language:switcher}

{exp
:weblog:entries weblog="home_page"}
<h2>{title}</h2>
{body}
{
/exp:weblog:entries}

</body>
</
html>

I don’t understand what is wrong? Sorry I’m a bit new to EE.

Profile
 
 
Posted: 12 May 2007 05:52 AM   [ Ignore ]   [ # 54 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

Oh geeze, that’s my fault.  When I changed the name of the extension I changed the tag to be

{exp:translator:simple}

Sorry, I’ll update the first post to reflect the change also.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
   
3 of 9
3
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64892 Total Logged-in Users: 60
Total Topics: 81822 Total Anonymous Users: 45
Total Replies: 439896 Total Guests: 277
Total Posts: 521718    
Members ( View Memberlist )