This may not really be an answer to your question, but the best way to make a multilingual is in most cases by using some simple PHP.
Create a folder called languages
and create the files lang.code.php
. Replace code
with, for example EN for English, DE for German, etc.
Create a language switcher with the following code:
<?php
$lang = "en";
if( isset( $_POST["lang"] ) ) {
$lang = $_POST["lang"];
setcookie ( 'lang', $lang, time() + 60*60*24*30, '/', 'YOUR_DOMAIN');
header( "Location: /" );
}
?>
No customization is needed.
Place the following PHP code on the page where you want your language switch to be.
session_start();
header('Cache-control: private'); // IE 6 FIX
if(isSet($_GET['lang']))
{
$lang = $_GET['lang'];
// register the session and set the cookie
$_SESSION['lang'] = $lang;
setcookie("lang", $lang, time() + (3600 * 24 * 30));
}
else if(isSet($_SESSION['lang']))
{
$lang = $_SESSION['lang'];
}
else if(isSet($_COOKIE['lang']))
{
$lang = $_COOKIE['lang'];
}
else
{
$lang = 'en';
}
if( $_COOKIE["lang"] == "en" ) {
$lang = 'en';
}
if( $_COOKIE["lang"] == "nl" ) {
$lang = 'nl';
}
switch ($lang) {
case 'en':
$lang_file = 'lang.en.php';
break;
default:
$lang_file = 'lang.en.php';
}
include_once 'languages/'.$lang_file;
For every language, add a new case. Change default
to the value that your default language should be.
Then, add the following HTML code to the same page as you placed the PHP code ^:
<form action="language_switcher.php" method="post">
<select name="lang">
<option value="en"<?php if( $_COOKIE["lang"] == "en" ) { echo " selected"; } ?>>English</option>
</select>
<button type="submit" class="btn btn-warning btn-small">Submit</button>
</form>
Add an option for every language that your website should have. The code assumes that your PHP language switcher is called language_switcher.php
.
A language file looks like this:
/*
------------------
Language: English
------------------
*/
$lang = array();
// Head
$lang['HEADER_TITLE'] = 'Portal';
// Menu
$lang['HOME'] = 'Home';
$lang['ADMIN'] = 'Admin';
Then, replace all the text in your website with:
<?php echo $lang['VAR']; ?>
where VAR
will represent a value in the language file.
It looks harder than it is.
Good luck!