gettext in php (with poEdit), translating a variable

664 views Asked by At

I have to work on a website made by someone else and I have to translate it to english (the website is in french). I tried to do it using gettext and PoEdit but I have some trouble with variables lately... This website is using an array to get the error messages for a formular and I tried to do this :

$tabError['titre'] = _("<p>Veuillez entrer un titre.</p>");

and I also tried to do this.

$error_trans =  _("<p>Veuillez entrer un titre.</p>");
$tabError['titre'] = $error_trans;

The error returned by php to me is :

Fatal error: Call to undefined function _() in C:\wamp\www\Dropbox   \Dropbox\www\Alter\addAnnonce.php on line 62

The code of the website is not very clean and it is a pain to edit ... Is there any way to translate the String that contains my variable ?

1

There are 1 answers

0
Václav Slavík On

Did you read the error? It tells you what the problem is right there: no such function exists. This is completely unrelated to Poedit or "variables". If you indeed get the same error for gettext, then your build of PHP is compiled without gettext or has the gettext module disabled.

There are clear and detailed instructions on how to ensure gettext is enabled in PHP manual: http://php.net/manual/en/book.gettext.php