3

I'm trying to use gettext on a website, and for that I'm following the O'Reilly Media tutorial. At the end of page one, it is saying that I need to use the command xgettext -n *.php, but my command line returns the following: 'xgettext' is not recognized as an internal or external command, operable program or batch file. I'm running my website on XAMPP, so the my whole directory is like this: xampp/htdocs/gettext/locale/en/lc_messages/

I have my test.php in the gettext folder, and the messages.po in the en folder. Even when I try to use poedit, it doesn't work. Here is my test.php code:

<?php
// I18N support information here
$language = 'en';
putenv("LANG=$language"); 
setlocale(LC_ALL, $language);

// Set the text domain as 'messages'
$domain = 'messages';
bindtextdomain($domain, "localhost/gettext/locale"); 
textdomain($domain);
echo "<br>";
echo gettext("A string to be translated would go here");
?>

I'm not really sure the string in the bindtextdomain function is correct. Anybody have any clue?

EDIT.:I forgot to mention that I was using Windows. I've already checked the php directory, the gettext extension is there, and it is enabled in the php.ini configuration file.

Adam Silva
  • 1,013
  • 18
  • 48
  • Make sure you've got it installed: `sudo apt-get install gettext` (if running a lamp setup) – MackieeE Apr 14 '15 at 11:31
  • My bad, I forgot to mention that I was using Windows. I've already checked the php directory, the gettext extension is there, and it is enabled in the php.ini configuration file. – Adam Silva Apr 14 '15 at 11:33
  • Well, I should of noticed anyway because `XAMPP` :) Looks like you might need a different approach http://stackoverflow.com/a/10610166/292735 – MackieeE Apr 14 '15 at 11:36

1 Answers1

3

I've found solution! Try add this line

putenv("LANGUAGE=$language"); 

According to Ubuntu wiki:

(Note that previously Ubuntu used the LANG variable for translation language. Now LANGUAGE is used for this, and LANG is used to specify other types of locale information, such as date formats, number formats, etc.)

Dmitriy Apollonin
  • 1,418
  • 2
  • 16
  • 30