Download and unzip multi_language.zip, then follow the steps below.
ExpressionEngine 2.x:
$assign_to_config['global_vars'] = array(
"base_url" => "http://www.mysite.com/",
"user_language" => "en"
);
ExpressionEngine 1.x:
$global_vars = array(
"base_url" => "http://www.mysite.com/",
"user_language" => "en"
);
Download and unzip the latest version of multi_language.zip, then follow the steps below.
ExpressionEngine 2.x:
ExpressionEngine 1.x:
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"
);
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.
{exp:multi_language:phrase index="hello"} to everyone!
<a href="{base_url}about">{exp:multi_language:phrase index="about"}</a>
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}
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 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]