0

Everything work fine with poedit and the creation of.po files. The problem is my PHP file that is sending me a message error all the time:

Fatal error: Cannot redeclare _() in C:\xampp\htdocs\gettextdemo\demo.php on line 12

This is the code of the php file

<?php /* Date de création: 2014-03-16 */ ?>
<html>
<body>
<?php
require_once("lib/streams.php");
require_once("lib/gettext.php"); 
$locle_lang = $_GET['lang'];
$locale_file = new FileReader("locale/$locle_lang/LC_MESSAGES/messages.mo");
$locale_fetch = new gettext_reader($locale_file);
function _($text)   
{
global $locale_fetch; 
return $locale_fetch->translate($text);
}
?> 
<h1><?php echo _("The best place in the world to get some text") ?> </h1> <p>
<?php echo _("the greatest son fo the bayou") ?> </p>
</body>
</html>

Sorry I can't figure out the mistake

Thank you

  • [`_()` is an alias to `gettext()`](http://www.php.net/manual/en/function.gettext.php). You cannot name your function as `_`. – Antony Mar 17 '14 at 14:20

1 Answers1

0

The Function _ is a reserved function from gettext. Rename it! For example:

<?php /* Date de création: 2014-03-16 */ ?>
<html>
    <body>
        <?php
            require_once("lib/streams.php");
            require_once("lib/gettext.php"); 
            $locle_lang     = $_GET['lang'];
            $locale_file    = new FileReader("locale/$locle_lang/LC_MESSAGES/messages.mo");
            $locale_fetch   = new gettext_reader($locale_file);

            function __($text) {
                global $locale_fetch; 
                return $locale_fetch->translate($text);
            }
        ?> 
        <h1><?php echo __("The best place in the world to get some text") ?> </h1> <p>
        <?php echo __("the greatest son fo the bayou") ?> </p>
    </body>
</html>
Adrian Preuss
  • 3,228
  • 1
  • 23
  • 43