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

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.

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
18 years ago
Lisa Wess's avatar Lisa Wess

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. =)

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

Sure thing Lisa!

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
18 years ago
Lisa Wess's avatar Lisa Wess

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

       
ms's avatar
ms
274 posts
18 years ago
ms's avatar ms

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

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

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.

       
ms's avatar
ms
274 posts
18 years ago
ms's avatar ms

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

       
ms's avatar
ms
274 posts
18 years ago
ms's avatar ms

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.

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

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.

       
ms's avatar
ms
274 posts
18 years ago
ms's avatar ms

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”).

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

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

       
Ryan Irelan's avatar
Ryan Irelan
444 posts
18 years ago
Ryan Irelan's avatar Ryan Irelan

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

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

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…

       
Ryan Irelan's avatar
Ryan Irelan
444 posts
18 years ago
Ryan Irelan's avatar Ryan Irelan

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! 😉

       
Rob Quigley's avatar
Rob Quigley
236 posts
18 years ago
Rob Quigley's avatar Rob Quigley

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).
       
1 2 3 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.