Your EE module, plugin, and extension marketplace!
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.
* Current version 1.01 (released 11 February 2009)
* Works with ExpressionEngine 1.6 and higher.
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.
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.
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.
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.
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}
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>
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.
Download and unzip multi_language.zip, then follow the steps below:
$global_vars = array( "base_url" => "http://www.mysite.com/", "user_language" => "en" );
{path=home} with {base_url}home in your templates to maintain the user's language in links
By purchasing the Multi Language Module you agree to the following conditions:
Posted by Nathan on 4th Jun 2009
This is an EXCELLENT module and I will recommend it to anyone attempting to turn their EE site into a multi-language site.
You can be expecting a long time customer and again, Ben, thank you for all of your help and for designing such a wonderful module!