Page 1 of 1

[SOLVED] Problem with gettext

Posted: Thu Jul 14, 2011 9:48 am
by Ignatius881
Hello.

I'll explain my problem.

First of all, I have to say that I'm using Linux and I have Apache, PHP, MySQL, phpmyadmin and two packages called php-gettext and poedit.

Well, I've followed several tutorials in Internet to make a multilingual webpage, or even a file. So, I create a file called test.php and I write this:

Code: Select all

<?
echo _("Hello world");
?>
Then I create the .po file and the directories (locale/language_COUNTRY/LC_MESSAGES). I copy the file messages.po into locale/en_GB/LC_MESSAGES, then I write the translation and move messages.po (which I've made a copy from) into locale/es_ES/LC_MESSAGES. And I create the .mo files.

Finally, I edit the test.php file in this way:

Code: Select all

<?
$language=(isset($_REQUEST['language']))?trim(strip_tags($_REQUEST['language'])):"en_GB";
putenv("LC_ALL=$language");
setlocale(LC_ALL, $language);
bindtextdomain("messages", "./locale");
textdomain("messages");

print "<p><a href=\"".$_SERVER['PHP_SELF']."?language=en_GB\">English</a> -
<a href=\"".$_SERVER['PHP_SELF']."?language=fr_FR\">French</a> -
  <a href=\"".$_SERVER['PHP_SELF']."?language=es_ES\">Espa&ntilde;ol</a></p>\n";

echo _("Hello world");

?>
And here is the problem: I can't see the text translated, only the original version. No matter what I do, I never can see the translations.

Can you help me? I hope I've explained everything well.

EDIT: I've followed this tutorial, step by step: http://mel.melaxis.com/devblog/2005/08/ ... g-gettext/

And I can't see the text in German, only and always in English :banghead:

Re: Problem with gettext

Posted: Thu Jul 14, 2011 10:00 pm
by Christopher
Ignatius881 wrote:And I can't see the text in German, only and always in English :banghead:
If you want to see translations in German, you need to create a file "locale/de_DE/LC_MESSAGES/messages.po" and generate a .mo file for it.

Re: Problem with gettext

Posted: Fri Jul 15, 2011 6:11 am
by Ignatius881
Christopher wrote:
Ignatius881 wrote:And I can't see the text in German, only and always in English :banghead:
If you want to see translations in German, you need to create a file "locale/de_DE/LC_MESSAGES/messages.po" and generate a .mo file for it.
Yes, that's what I've done time and again, but nothing.

I also added extension=gettext.so into the php.ini file, that is located in /etc/php5/apache2 (and another in /etc/php5/cli), and I restarted apache.

Re: Problem with gettext

Posted: Fri Jul 15, 2011 9:40 pm
by Christopher
What is the value of:

$language=(isset($_REQUEST['language']))?trim(strip_tags($_REQUEST['language'])):"en_GB";

Re: Problem with gettext

Posted: Sat Jul 16, 2011 4:03 pm
by Ignatius881
Christopher wrote:What is the value of:

$language=(isset($_REQUEST['language']))?trim(strip_tags($_REQUEST['language'])):"en_GB";
Mmm, how can I know that? I'm not an expert with PHP :oops:

Re: Problem with gettext

Posted: Sat Jul 16, 2011 4:35 pm
by Christopher
You don't need to be an expert to know this: ;)

Code: Select all

$language=(isset($_REQUEST['language']))?trim(strip_tags($_REQUEST['language'])):"en_GB";
echo "language=$language<br/>";

Re: Problem with gettext

Posted: Mon Jul 25, 2011 8:45 am
by Ignatius881
Excuse me, I was on holiday.

Okay, I was working again with gettext, with no success. I've followed this link again, http://mel.melaxis.com/devblog/2005/08/ ... g-gettext/, step by step again.

Even I've installed Chinese and Japanese locales, translations and fonts to work with them in Ubuntu, but nothing.

I don't know if I'm doing something wrong or not (maybe yes).

Can you show me other tutorials, or your .php files?

Re: Problem with gettext

Posted: Sat Jul 30, 2011 11:03 am
by Ignatius881
Ok, I solved the problem. It was a stupid thing, but I had to write "en_GB.utf8" instead of "en_GB", according to the output command locale -a :oops:

Well, thanks for your help.

Re: [SOLVED] Problem with gettext

Posted: Mon Aug 01, 2011 5:56 am
by VladSun
Don't use $_SERVER['PHP_SELF'] - it's XSS vulnerable.