Multi Language Module

*** Update: now compatible with EE2.0

The Multi Language Module is an Expression Engine add-on that allows you to create phrases in multiple languages, which you can then display in your site templates and call from other add-ons. It comes with 3 languages by default (English, Spanish, Italian) but you can add and delete languages as you please.

Support can be found in the comments and in this EE forum thread.

Download Multi Language Module
Current Version: 2.0 (released 9 June 2010)

* Works with ExpressionEngine 2.0 and ExpressionEngine 1.6

1. Concept

To create a phrase you simply enter a phrase index and add the phrase in as many languages as you want.

To display a phrase, you simply use an expression of the format {exp:multi_language:phrase index="hello"}. Depending on the user's language, this will appear as "hello", "hola", "ciao", etc., assuming you have already entered these translations.

The user's language is determined by the url. So for a webpage at mysite.com/links/ the italian version will be at mysite.com/it/links/. This makes for easy navigation and setup in Expression Engine.

2. How It Works

The Multi Language Module uses a global variable in the path.php file to determine the current language. This is then used to retrieve phrases and weblog entries in the user's current language.


Setting the Global Variables in EE2.0

First, open up the index.php file in your website's root directory. Uncomment and set the global variables in the following line:

$assign_to_config['global_vars'] = array(
"base_url" => "http://www.mysite.com/", 
"user_language" => "en"
);
				

Change mysite.com to your domain. In this case English (en) is your default language.

Each new language requires a folder, for example "es" for Spanish, to be created in your website's root directory. Create a directory, copy the index.php file from your root directory and make the following changes (example for Spanish):

$assign_to_config['global_vars'] = array(
"base_url" => "http://www.mysite.com/es/", 
"user_language" => "es"
);
				


Setting the Global Variables in EE1.6

First, open up the path.php file in your website's root directory. Set the global variables in the last line:

$global_vars = array(
"base_url" => "http://www.mysite.com/", 
"user_language" => "en"
);
				

Change mysite.com to your domain. In this case English (en) is your default language.

Each new language requires a folder, for example "es" for Spanish, to be created in your website's root directory. Open the path.php file in that directory and set the global variables as follows:

$global_vars = array(
"base_url" => "http://www.mysite.com/es/", 
"user_language" => "es"
);
				

You will now have two new global variables available to you in your templates and add-ons.

base_url can be used for adding links in your templates while keeping the language in your url.

user_language contains the current language.


Creating and retrieving multi-lingual phrases

Phrases can easily be created on the Multi Language Module page. Just enter a phrase index, which will be used to reference the phrase, and then enter it in as many languages as you want.

To retrieve a phrase in the templates, use {exp:multi_language:phrase index="hello"}, replacing hello with the phrase index.

Screenshot

Screenshot


Multi-lingual Weblogs

Weblogs can be easily set up to handle multi-lingual fields. For each new language, just add a custom weblog field for title and body.

To add Spanish for example, add one custom field called title_es and one called body_es. These can then be used to hold the translations of the default title and body fields.

Then in your templates use the following method for calling weblogs:

{exp:weblog:entries weblog="my_weblog"}
{if user_language == "en"}{title}{if:else}{title_{user_language}}{/if}
{if user_language == "en"}{body}{if:else}{body_{user_language}}{/if}
{/exp:weblog:entries}
				

Screenshot


Switching Languages

You can switch language using javascript and php, but in my opinion the best way is to use a permanent link (for SEO purposes):

<a href="{site_url}{if segment_1}{segment_1}/{/if}{if segment_2}{segment_2}/{/if}{if segment_3}{segment_3}/{/if}">View site in English</a>
<a href="{site_url}es/{if segment_1}{segment_1}/{/if}{if segment_2}{segment_2}/{/if}{if segment_3}{segment_3}/{/if}">Ver sitio en Espańol</a>
				


Removing index.php from your URL

If you use the exclude list method to remove index.php from your URL then you must add each language as an exception to the rule. For example:

RewriteEngine on
RewriteCond $1 !^(es|it|images|system|themes|index\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L] 
				

The language directories already include a .htaccess file that removes index.php.

3. Installation

Download and unzip multi_language.zip, then follow the steps below.

For EE2.0

  1. Open the multi_language_2_0 folder
  2. Upload the multi_language folder to the system/expressionengine/third_party folder
  3. Add two new global variables to the index.php file in the root directory of your site, changing mysite.com to your domain:
    $assign_to_config['global_vars'] = array(
    "base_url" => "http://www.mysite.com/", 
    "user_language" => "en"
    );
    					
  4. Create language folders such as es and it in the root directory of your site, changing system_path if necessary and mysite.com to your domain in the index.php file in each folder
  5. Duplicate the es folder for each new language you want, changing user_language to your domain in index.php, and upload it to the root directory of your site
  6. Install the Multi Language module
  7. Add or delete languages in the module (add labels for new languages in the lang.multi_language.php file)
  8. Start adding phrases in the module
  9. You can replace {path=home} with {base_url}home in your templates to maintain the user's language in links

For EE1.6

  1. Open the multi_language_1_6 folder
  2. Upload the multi_language folder to the system/modules folder
  3. Upload lang.multi_language.php to the system/language/english folder
  4. Add two new global variables to the path.php file in the root directory of your site, changing mysite.com to your domain:
    $global_vars = array(
    "base_url" => "http://www.mysite.com/", 
    "user_language" => "en"
    );
    					
  5. Upload the es and it folders to the root directory of your site (if you want those languages), changing system_path if necessary and mysite.com to your domain in the path.php file in each folder
  6. Duplicate the es folder for each new language you want, changing user_language to your domain in path.php, and upload it to the root directory of your site
  7. Install the Multi Language module (Control Panel -> Modules -> Install)
  8. Add or delete languages in the module (add labels for new languages in the lang.multi_language.php file)
  9. Start adding phrases in the module
  10. You can replace {path=home} with {base_url}home in your templates to maintain the user's language in links

4. Download

Each individual license costs $39.95, which allows you to use the module on one installation of EE. You must purchase a license in order to download the Multi Language Module. Once you have completed payment you will be sent a code that will allow you to download the file.

*** Non-profit organisations, students and anyone who would like to exchange something for this module, email me at and you can have it for free!

By purchasing the Multi Language Module you agree to the license agreement.

If you have already purchased the Multi Language Module then you can download it by entering your email and code below.

Email:
Code:

5. License

By purchasing the Multi Language Module you agree to the following conditions:

  • One license grants the right to perform one installation of the Multi Language Module. Each additional installation requires an additional purchased license.
  • You may not reproduce, distribute, sell or transfer the Multi Language Module, or portions thereof, to any third party.
  • All copyright and proprietary notices within the Multi Language Module files must remain intact and unaltered.
  • The Multi Language Module is provided "as is", without warranty of any kind.
  • You assume all risk associated with the installation and use of the Multi Language Module.

6. Changelog

Version 2.0
  • Converted to an EE 2.0 compatible module (both versions available in download)
Version 1.01
  • Fixed a bug which showed an update notification when no update was available
  • Made remove and add language buttons visible when no phrases exist

7. Comments

Blank Avatar
Tim
09 January 2009


Hello,

just bought your multi language extension. I'm installing it, but I cannot find the configuration setting mentioned in "(7) Add or delete language in the module".

Can you help urgently?
thx,
Tim

Blank Avatar
Ben
09 January 2009


hi tim,
when you go to the multi language module page you will see a table containing the phrases you have entered. at the top of the table, next to each language is a remove link which removes that language. on the right hand side there is the add language link.

Blank Avatar
Tim
09 January 2009


Hello Ben,

thanks for the lightning fast answer... I see it know, but it's really well hidden in case of a new install since you have to have at least 1 entry before the language are shown.

Something you might want to consider to change in following versions... not necessary for me anymore though, since I know it now.

have a nice weekend,
Tim.

Blank Avatar
Ben
10 January 2009


thanks for the tip, i'll fix it in next release

Blank Avatar
Jim Pannell
13 January 2009


This looks great Ben and will definitely be useful for the multilingual sites I'm working on!

Blank Avatar
Nathan
14 January 2009


Hello Ben,
I just downloaded your extension and I'm having some trouble getting it installed. I've copied the language files to my system/language folder but when I attempt to put in one of the urls, for example mysite.com/es/ I'm getting a 404 error. Am I missing something?

I'm new to the whole Expression Engine setup so a more detailed walkthrough on how to fully install this would be VERY MUCH APPRECIATED.

Thank you so much for your time!

Blank Avatar
Nathan
14 January 2009


I figured it out! For some reason when you extract folders or files for use on the web from a zip file it screws up the permissions. Simply re-create the files and folders then copy and paste the info into them and poof! Your web server will have access to the files.

Blank Avatar
Ben
14 January 2009


hi nathan, i was just replying to your previous comment when i saw this, glad you got it working!

Blank Avatar
Nathan
14 January 2009


My next question is, should the Global Variables be loaded by themselves once entered into the path file or do I need to create them myself through the template tab? I ask because they aren't automatically there and I'm not sure what info is needed to create them myself.

Blank Avatar
Ben
14 January 2009


yes the global variables will be loaded directly from the path.php file, no need to create them again.

Blank Avatar
Nathan
14 January 2009


WoW Ben, thanks for the incredibly speedy response. I'm sorry to pester but it's a very large project I'm working on atm and if I can get this working properly you can expect me to be purchasing SEVERAL more licenses.

The Global Variables are not being loaded automatically but everything seems to be done correctly and I've followed your directions to the T. Any ideas as to what could be causing this problem?


» View more comments


Leave A Comment

name (required)
email (required but will be kept completely private)
website