Multi-lingual ExpressionEngine (practical)

Last year at EECI in Leiden, I discussed approaches to multi-lingual sites in ExpressionEngine

Last year at EECI in Leiden, I discussed approaches to multi-lingual sites in ExpressionEngine.

In March I got the opportunity to work with my pal Andy at Stuff and Nonsense to make his client, Emyr Evans, site bi-lingual.

As I discussed in my talk last year, there are many approaches now in EE including Transcribe from my good friends at EE Harbor, the Carl Crawley approach and Biber.

We didn't use any of those in this project.

What we did use was Freebie (one of my favourite little EE tools) and Republic Variables.

Andy had already built out the majority of the site in traditional EE fashion before I got involved.

URL Structure

The first step was to create the URL structure that would define what language the user would be looking at and so opted for /en and /cy - pretty simple. Of course, there are no template groups called 'en' or 'cy' which would make EE fail by default. Enter Freebie.

Using Freebie you can tell it to ignore the presence of certain strings in the segments.

Channel Fields

From here I duplicated each channel field (unsustainable for anything more than 2 languages IMHO) and appended a language indicator (that must match our Freebie segments) to each.

So that handled all of the channel field data for us. As I said, anything more than 2 languages and you'll start running into problems. It's not particularly efficient to continue to add new fields each time a new language comes on-board, on a site like this with only a handful of channels, it's manageable.

custom fields for a channel with language indicators

Misc Content

There's always content that doesn't belong in a Channel but that you want your client to edit. For stuff like that I'd usually use Low Variables (an excellent add-on with many uses but on this project, I opted for Republic Variables for the simple reason that it we only needed text fieldtypes.

Again, just like the custom fields, I appended _en and _cy to the respective variables that we could then use within templates.

It was in Republic Variables that we stored translations for navigation, used equipment data titles and form labels, amongst others.

Republic Variables in the control panel

Templates

The first thing was to fix the homepage as it would never have any segments if you land on it. For this I used Switchee with some simple template code to redirect the user if there was no language segment.

 {exp:switchee variable = "{freebie_1}" parse="inward"}
    {case value="en|cy"}
    ....
    {/case}

    {case default="Yes"}
    {redirect='en'}
    {/case}

    {/exp:switchee}

Translating Content in Templates

Simply a matter of calling the appropriate channel field as we normally would with ExpressionEngine:

{exp:channel:entries channel="used" dynamic="no" limit="5"}
{cf_used_summary_{freebie_1}}
{/exp:channel:entries}

Of course for the content stored in Republic Variables we can do:

{rv_variablename_{freebie_1}}

Other Gotchas

On a page like this one, the user has the option to contact the tractor dealership about a specific model etc. For this I used Freeform and redirected a submission with this paramter:

{exp:freeform:form
	form_name="ask_a_question"
	return="{freebie_1}/confirmation"
	}

As you can see, Freebie gives quite a lot of power and with the right mix of add-ons, building a small bi-lingual site can be a nice experience.

The Emyr Evans site