1 of 8
1
Simple Translator (formerly known as Another Language Switcher)
Posted: 08 May 2007 06:08 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

So I’ve been bitten by the language switching bug and as such decided to create an EE based solution.  That means you won’t have to parse segments or learn php to get this to work, it should be as simple as creating a few fields.  Furthermore it should work with existing data, so if you’ve been waiting to go international it shouldn’t take much more than installing this.

That said, the configuration is done in the extension settings.  Once there, you’ll see some helpful tips, but the long and short of it is that you’ll create a bunch of lines like this:

_ja:Japanese

What that means is if a user is browsing the site in japanese it should display fields with a ‘_ja’ suffix instead of no suffix (where available).  So, if you have a field named ‘body’ and another field named ‘body_ja’ and the user is using Japanese the body_ja would get rendered instead of the body field.

Finally, to output the language switcher links simply place {exp:translator:simple} in your templates.

This extension also alters the search and profile pages by linking up with the built in EE language packs.  All you need to do is make sure the title of your language has the same name as the folder of the language pack.  So in the above example you would need a language pack named ‘Japanese’ in your /system/languages folder.  Take note that case does matter, so if your title is Japanese then your folder should have a capital J.  If it does not you should be able to rename the folder without too much trouble. (This will only work in PHP5 due to some inconsistencies in object references.  The friendly folks at Ellis Lab have looked into a fix for this and when it is implemented I will make sure this extension takes advantage of that.)

To switch category groups you can use the same suffix as you do with weblog fields.  So if you have a category group named ‘Blog’ and a user is browsing in Japanese it would use a category group named ‘Blog_ja’ instead of just ‘Blog’.  In order for this yo work you have to place `{exp:translator:simple category_group="4"}` wherever you would normally place the category group.  So if the ‘Blog’ category group had an id of 4 and you wanted to switch it out in a weblog:categories tag, you could do that like so:

{exp:weblog:categories weblog="blog" category_group="{exp:translator:simple category_group="4"}"}…{/exp:weblog:categories}

The same also now works for switching entire weblogs:

{exp:weblog:entries weblog="{exp:translator:simple weblog="blog"}"}…{/exp:weblog:entries}

The category_group and weblog MUST be surrounded with double quotes, single quotes WILL NOT WORK.

That’s it, it should be pretty simple, but of course, let me know if it’s not.

File Attachments
ext.simple_translator_109.zip  (File Size: 6KB - Downloads: 452)
 Signature 

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

Profile
 
 
Posted: 08 May 2007 06:09 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  31055
Joined  05-14-2004

Mark, this looks amazing and highly desired.  If you get a chance, I hope you’ll pop a link to it in the wiki multi-lingual tutorials and the extension list. =)

 Signature 
Profile
MSG
 
 
Posted: 08 May 2007 06:15 PM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

Sure thing Lisa!

 Signature 

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

Profile
 
 
Posted: 08 May 2007 06:23 PM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  31055
Joined  05-14-2004

Thank you, sir.  I just want to make sure people know about this. =)

 Signature 
Profile
MSG
 
 
Posted: 08 May 2007 07:19 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  756
Joined  03-16-2002

Hi Mark,

tried to play with the extension, but I get the following error when accessing the extension manager:

Parse error: parse error, unexpected T_OBJECT_OPERATOR in /.../extensions/ext.language_switcher.php on line 198

Both files seem to be in the correct place and I already tried a new upload. Any ideas?

-Markus

 Signature 

Markus Stolpmann • Expression Engine 1.6.4
Current project: kamaco.info - (german) website for Austrian publication coach K. Matejcek

Profile
 
 
Posted: 08 May 2007 07:53 PM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

That should be fixed now.  It’s my fault for not checking this in PHP4.  I developed it in 5 and used a few ‘new’ features apparently.

 Signature 

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

Profile
 
 
Posted: 08 May 2007 08:03 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  756
Joined  03-16-2002

Yepp ... fixed.
Thanks a million for this ultrafast response, Mark

 Signature 

Markus Stolpmann • Expression Engine 1.6.4
Current project: kamaco.info - (german) website for Austrian publication coach K. Matejcek

Profile
 
 
Posted: 08 May 2007 08:21 PM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  756
Joined  03-16-2002

Works great, Mark. Might be very useful at some time. Really appreciate all your work!

But I have two questions regarding usage:

1. Is it possible to change the title as well? I’ve added a field named title_de, but that doesn’t seem to work.

2. Any possibility to check which language is selected from inside the template? Seems the switch isn’t done via a URL segment.

 Signature 

Markus Stolpmann • Expression Engine 1.6.4
Current project: kamaco.info - (german) website for Austrian publication coach K. Matejcek

Profile
 
 
Posted: 08 May 2007 08:34 PM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

Whoops, that was for a rather selfish reason where I required the weblog name prior to the field name as that is my personal naming scheme.  Anyway I’ve switched it around and a field ‘title_jp’ should override the ‘title’ field now.

 Signature 

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

Profile
 
 
Posted: 08 May 2007 09:23 PM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  756
Joined  03-16-2002

Thanks in advance ... but it seems that I have to bring the bad news all the time :-( : The file seems to be broken (0 kb, “no valid archive").

 Signature 

Markus Stolpmann • Expression Engine 1.6.4
Current project: kamaco.info - (german) website for Austrian publication coach K. Matejcek

Profile
 
 
Posted: 08 May 2007 09:28 PM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

Huh, that only seems to happen from my home ISP, either way it should be sorted out now.

 Signature 

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

Profile
 
 
Posted: 08 May 2007 09:54 PM   [ Ignore ]   [ # 11 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  306
Joined  02-02-2006

Hi Mark. This looks nice. Thanks for posting it. For a minute there I thought you had saved me a bunch of time, but, alas, I need category (sub navigation) and main navigation to also change when the language is switched, so i’ll still need to go custom. smile However, I’m interested in talking to you about expanding this to something that covers categories, members etc. EE is in need of a robust solution for languages.

 Signature 

Learn EE with the ExpressionEngine Screencasts

Ryan Irelan

Airbag Industries, LLC

Profile
 
 
Posted: 08 May 2007 10:17 PM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

well ryan, the biggest problem, is finding a place to store the translated content. we could store it in the category description but then that renders the description useless for it’s intended purpose.  the only other thing I can come up with is to create a global “translation key” where you can define translations to occur on a word-to-word basis.  then if any of the “keyed” words show up we can translate them based on the key…

 Signature 

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

Profile
 
 
Posted: 08 May 2007 10:23 PM   [ Ignore ]   [ # 13 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  306
Joined  02-02-2006

True, Mark. I’m definitely not into polluting other useful content fields. The translation key might be a possiblility, but I could see that getting very complex quickly.

In a very abstract sense, I’m thinking about just relating category groups. One group for English, one for Japanese, etc. How you would translate that into a workable and usable extension is another question entirely! wink

 Signature 

Learn EE with the ExpressionEngine Screencasts

Ryan Irelan

Airbag Industries, LLC

Profile
 
 
Posted: 09 May 2007 12:39 AM   [ Ignore ]   [ # 14 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  398
Joined  10-10-2004

Mark how does the extension know the user is “browsing japanese”? The extension is checking something with the browser - what exactly? Just curious. Thanks.

What that means is if a user is browsing the site in japanese it should display fields with a ‘_ja’ suffix instead of no suffix (where available).

Profile
 
 
Posted: 09 May 2007 12:52 AM   [ Ignore ]   [ # 15 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  451
Joined  10-14-2005
Mark Huot - 08 May 2007 06:08 PM

I’d be open to a discussion however on how to provide translations for those features.  Categories, specifically, are difficult because there is no place in the EE admin to enter an alternate language.

How about creating additional category groups suffixed with the language code?

 Signature 

Nathan Pitman

Nine Four Ltd - a member of the EEPro Network

Profile
 
 
Posted: 09 May 2007 01:34 AM   [ Ignore ]   [ # 16 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  14918
Joined  06-03-2002

Mark: first off, thank you for sharing this extension, and thank you for using the $SESS->cache array, appropriately prefixed. :-D

Some notes:

1) The table prefix is handled automatically when using $DB->query()
2) you might prefer to use $FNS->set_cookie() which honors the cookie prefs for the installation
3) Member custom fields could potentially be used to recreate the default fields in different languages.  This would either require some setup by the user, or some automation by the extension, which would be best handled as an option and not a blind database manipulation.
4) Categories.  I believe some changes I have made for 1.6 will assist you, but I can offer nothing concrete as implementation remains fluid until I am happy with it.  For the present time, Ryan’s suggestion is perhaps a good idea.

 Signature 
Profile
MSG
 
 
Posted: 09 May 2007 05:38 AM   [ Ignore ]   [ # 17 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

@Ryan and Nathan

Great ideas!  I love the idea of using a separate category group to define the translations.  It will take a little bit of tweaking, but I think something along those lines could work quite well.  The biggest challenge there is that you’d have to be very anal about keeping your category groups in sync.

@Derek,

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?
2. $FNS->set_cookie it is, I forgot that existed.
3. I guess member fields could work the same way that weblog fields work in that respect.  If the suffix’d version of a member field exists go with that, not the default field.
4. Ooooo, 1.6!  Sounds exciting.

@Rob,

Derek kind of gave it away, but when you click a language it redirects you to a new page with the /lang/_ja(suffix) appended to the end.  That set’s a cookie and then redirects you back to the page without the suffix.

 Signature 

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

Profile
 
 
Posted: 09 May 2007 05:47 AM   [ Ignore ]   [ # 18 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  865
Joined  02-05-2002

Very nice Mark!

A great addition to the various Multi Language efforts.

Unfortunately it uses the exact same name as my language switcher extension…
(the one that changes a logged in member’s Localization Settings based on the ‘language’ variable set in path.php)

See this wiki article

 Signature 

Member of the EE Pro Network

Profile
 
 
   
1 of 8
1
 
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 10:33 AM
Total Registered Members: 60703 Total Logged-in Users: 37
Total Topics: 73143 Total Anonymous Users: 19
Total Replies: 394496 Total Guests: 563
Total Posts: 467639    
Members ( View Memberlist )