I've been working in translations for customly designed webs for a while and those needed translations, so what I'm currently doing for translating the text is the following:
I have multiple files that have a bunch of PHP files that contain the strings in multiple languages. Each file has the same constant declared exactly the same. Like this:
define('MENU_ITEM1','WHO ARE WE?');
define('MENU_ITEM2','PROFESSIONAL ACTIVITY');
define('MENU_ITEM1','¿QUIÉN SOMOS?');
define('MENU_ITEM2','ACTIVIDAD PROFESIONAL ');
Then, on the menu I have the language selector. The select creates a get variable on the url displaying the selected language, like this:
<select id="select" onChange="idioma(this.value);">
<option value="ES">Español (ES)</option>
<option value="EN">English (EN)</option>
...
</select>
This calls a function that adds a get to the url. Like this (for every language):
location.href=url+"?lang=ES";
So in another file, we have a PHP switch that takes the language from the url and creates a cookie that includes the right language file. If the cookie is not set, we have a default language. It would be something like this:
<?php
if(isSet($_GET['lang'])){
$lang = $_GET['lang'];
$_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 = 'ES';
}
switch ($lang) {
case 'EN':
$lang_file = 'en/lang.en.php';
break;
case 'ES':
$lang_file = 'es/lang.es.php';
break;
default:
$lang_file = 'es/lang.es.php';
}
include_once $lang_file;
?>
So by this teeeedious process, the web is traslated. Issue: I have the slight feeling that this is not an optimal solution, so if anyone has a way to fix it or do it in any other way, it would be so helpful. Note that I do not work with WordPress, so WP plugins are out of the question (I worked with them, I know they exist). I've seen webs that use subdomains (en.something.com
) or other folders (something.com/en/
) but I'm not really sure how to do that.