Firstly, we’re going to start with a blank ExpressionEngine Install:

#

Now what we need to do is to define our content languages/countries. We do this by creating root folders for each country that we want. For the purpose of this article, I’m going to create an English (en), French (fr) and Spanish (es).

#

I personally choose to use the two letter abbreviations of countries so that I keep my URL’s small enough (www.sitedomain.com/en/) rather than using the full name (www.sitedomain.com/english/) – but this is entirely up to you.

we now need to copy the ‘/index.php’ and the ‘/path.php’ files into each of the folders that we just created.

#

We don’t need to change anything in the index.php files since they are exactly the same, but we do need to make some changes on the path.php files.

Default File :

1. <?php
2.
3. // ------------------------------------------------------
4. // DO NOT ALTER THIS FILE UNLESS YOU HAVE A REASON TO
5.
6. // ------------------------------------------------------
7. // Path to the directory containing your backend files
8.
9. $system_path = "./system/";
10.
11. // ------------------------------------------------------
12. // MANUALLY CONFIGURABLE VARIABLES
13. // See user guide for more information
14. // ------------------------------------------------------
15.
16. $template_group = "";
17. $template = "";
18. $site_url = "";
19. $site_index = "";
20. $site_404 = "";
21. $global_vars = array(); // This array must be associative
22.
23. ?>

Change 1) Change line 9 to represent the new path to the system folder

9. $system_path = "../system/";

Change 2) Change line 18 to include the URL of the site (including the folder segment)

18. $site_url = "http://www.sitedomain.com/en/";

Change 3) Create an Array value in line 21 to include a country reference that you will use within your Custom Fields.

21. $global_vars = array(
"countrycode"=>"English"
); // This array must be associative

Do that for each of the languages/folders that you have created passing the correct folder/language into the appropriate section.

Now you have a working folder structure with languages – try visiting http://www.sitedomain.com/en/ and you should see your EE Homepage!

Part 2 : Referencing Custom Fields

Now we need to create a custom field to associate our content/language. There are multiple ways you can do this, but I simply do it by creating a custom field called {cat}_lang – for example, my news section would be ‘news_lang’ or my about section would be ‘about_lang’. You can do this how you want though.

Next you set the custom field to be a drop down and you pre-populate the fields with the same values as you entered in the associative array (change 3). As the following example shows.

#

Now once you’ve done this, you will be able to publish an entry and choose it’s appropriate language – keeping all your news in the ‘news channel’ and so on so forth.

All you now need to do is to amend your standard exp:weblog:entries code to allow for the filter of the language/location. This is where the ‘countrycode’ global array comes into it’s own – simply add the following to your exp:weblog:entries code:

search:news_lang="{countrycode}"

Et Voila!

One last thing you should probably also consider is that if someone went to ‘www.sitedomain.com’ – it wouldn’t show them anything because you have no language settings etc. I simply use a .htaccess file in the root and add the following line to redirect the user to a’default’ location (i.e the English site):

Redirect 301 /index.php http://www.sitedomain.com/en/


UPDATE: EE2.1 Users

Ok – it’s in fact, even easier in EE2.1 (don’t you just love progress!)… Easiest way, I’ve found to do it is as follows:

1) Create your Language folders are per the set up above, then copy the /index.php file into the folder you’ve created.

2) Open the index.php file you’ve just copied and make the following tweaks:

$system_path = '../system';

Note the double dot (..) instead of the one.

Then uncomment line #73 :

$assign_to_config['global_vars'] = array();

This is where you set your variables as per the instructions above, for example:

$assign_to_config['global_vars'] = array(
"countrycode"=>"English"
); // This array must be associative

and finally, uncomment the following:

$assign_to_config['site_url'] = '';

and make sure you put the URL in with the language slug as well, e.g:

$assign_to_config['site_url'] = 'http://www.site.com/fr';

And thats it!