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.
