1

I have all the files and languages set in the right place yet I get an error for 'redeclaring' the function _ Here's my code:

include("../application/libs/languages/libs/streams.php");
include("../application/libs/languages/libs/gettext.php");


$locale_file = new FileReader("application/libs/languages/locale/en_gb/en_GB.mo");
$locale_fetch = new gettext_reader($locale_file);

function _($text){
    global $locale_fetch;
    return $locale_fetch->translate($text);
}

I'm not too sure why it's clashing wish another function as I haven't declared any like that. Here's my error:

Fatal error: Cannot redeclare _() in C:\xampp\htdocs\mvc\application\views_templates\header.php on line 12

The error line 12 is the ending } at the bottom of the code above

1 Answers1

0

_ is a language construct, an alias of Gettext

You could override it by using a different namespace

namespace myUnderscore;

function _($argument) {
   ...
}

But I'd probably just choose a new name for your function

andrew
  • 9,313
  • 7
  • 30
  • 61
  • I was wanting to use the function _ so I could echo the text like so: _("text"); as I've seen people use it, but it's broke on me :( I'm using gettext on the _ function it's just not working –  Dec 13 '14 at 03:42
  • you don't need to declare the function `_`, it already exists, just call it `_('text')` if you need to set the locale see the manula linked in the answer – andrew Dec 13 '14 at 03:46
  • heres some more info http://stackoverflow.com/questions/2401421/how-to-use-gettext-in-php – andrew Dec 13 '14 at 03:48
  • my folder is: C:\xampp\htdocs\mvc\application\libs\languages\locale\en_GB\LC_MESSAGES where my mo files are, how would I set up: setlocale(LC_ALL, 'en_GB'); bindtextdomain("LC_MESSAGES", "C:\xampp\htdocs\mvc\application\libs\languages\locale"); textdomain("LC_MESSAGES"); –  Dec 13 '14 at 04:04