Multi Language Module

Installation

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

ExpressionEngine 2.x:

  1. Open the multi_language_2_0 folder
  2. Upload the system/expressionengine/third_party/multi_language 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 (Control Panel > Add-Ons > Modules > Install)
  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

ExpressionEngine 1.x:

  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

Updating

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

ExpressionEngine 2.x:

  1. Overwrite the system/expressionengine/third_party/multi_language folder

ExpressionEngine 1.x:

  1. Overwrite the system/modules/multi_language folder
  2. Overwrite system//language/english/lang.multi_language.php

Setting the Global Variables in EE2

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

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.

Template Tags

{exp:multi_language:phrase index="hello"}
Outputs the phrase in the current language
{exp:multi_language:phrase index="hello"} to everyone!
{base_url}
Outputs your site url with the current language
<a href="{base_url}about">{exp:multi_language:phrase index="about"}</a>
{user_language}
Outputs the current language

Multi-lingual Channels

Channels can be easily set up to handle multi-lingual fields. For each new language, just add a custom 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}

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 in your .htaccess file. For example:

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

Each language directory should then contain a .htaccess file with the following code (change es to the appropriate value):

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