Stavo cercando di implementare gettext() nel mio codice, ma non riesco a farlo funzionare.
Sono sicuro che la libreria sia attiva, dato che sullo stesso host ci gira Wordpress senza problemi.
Il codice è dentro a includes/l10n.php:
Codice PHP:
<?php
$parentpath = dirname( dirname(__FILE__) );
$curpath = dirname(__FILE__).'/';
$locale = '';
function comeFrom() { //check which language is set by the user's browser
$hal = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$lang = substr($hal, 0, 2);
return $lang;
}
$locale = comeFrom();
setlocale(LC_ALL, $locale);
bindtextdomain($locale, $parentpath."locale");
textdomain($locale);
function __($text) // Return a translated string.
{ return gettext($text); }
function _e($text) // Echo a translated string.
{ echo gettext($text); }
function __ngettext($single, $plural, $number) // Return the plural form.
{ return ngettext($single, $plural, $number); }
?>
mentre nell'index.php (nella root), che richiama il file contenente il codice detto sopra, ho messo
Codice PHP:
<?php _e('Register'); ?>
e, nel file it.mo e it.po (dentro a includes/locale/it/LC_MESSAGES), c'è il corrispettivo tradotto "registrati".
Peccato che non funzioni.
Dov'è che sbaglio?