Me Particularmente like this systemZito, It’s simple and you can do a lot of things with it!
you can define the language by $_GET
, ie is by url
You can have as many languages as you need, and it’s easy to add translations!
Here is an example:
//Definir linguagens a ser usadas:
define('LANG_ENGLISH', 'en');
define('LANG_FRENCH', 'fr');
define('LANG_SPANISH', 'es');
// Definir linguagem principal
$language = isset($_GET['l']) ? $_GET['l'] : LANG_ENGLISH;
// Mini-função que faz o seu trabalho:
function t($string, $args = array(), $langcode = NULL) {
global $language, $translation;
// Set language code.
$langcode = isset($langcode) ? $langcode : $language;
// Search for a translated string.
if ( isset($translation[$langcode][$string]) ) {
$string = $translation[$langcode][$string];
}
// Replace arguments if present.
if ( empty($args) ) {
return $string;
} else {
foreach ( $args as $key => $value ) {
switch ( $key[0] ) {
case '!':
case '@':
case '%':
default: $args[$key] = $value; break;
}
}
return strtr($string, $args);
}
}
To add translations:
(in another file separately)
//index.php
// incluir a mini-função acima se tiver noutro ficheiro
include('inc.language.php');
// adicionar traduções a uma certa linguagem exemplo:
$translation[LANG_SPANISH] = array(
'Email' => 'email',
'Name' => 'nombre',
'Organization' => 'Organización',
'Phone Number' => 'Número de teléfono',
'Hello %name' => 'Hola %name',
);
In its use it would be something like:
//www.site.com/index.php?l=es
<text id="org"><?= t('Organization') ?></text>
// output: Organización