Page 1 of 1

Unable to get gettext to work

Posted: Thu Feb 23, 2006 11:38 am
by simon_stz
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I'm trying to start a new PHP project with multilingual support. I've installed apache and PHP successfully and  phpinfo() function tells me I've gettext support enabled. Gettext seems to work outside of PHP.

I've created the next simple code to test gettext under PHP (obtained from the official PHP doc examples):

Code: Select all

<html><head><title>Testing gettext</title></head>
<body>
<?php
// Set language to Spanish
setlocale(LC_ALL, 'es_ES');
// Specify location of translation tables
bindtextdomain("messages", "./locale");
// Choose domain
textdomain("messages");
// Translation is looking for in ./locale/es_ES/LC_MESSAGES/messages.mo now
// Print a test message
echo _("Hello world");
?>
</body></html>
To create translations tables I've followed official gettext doc as follows:

Code: Select all

# mkdir -p ./locale/es_ES/LC_MESSAGES

# xgettext *.php

# vi messages.po
# cat messages.po
msgid "Hello world"
msgstr "Hola mundo"

# msgfmt -v messages.po
1 translated message.

# cp messages.mo ./locale/es_ES/LC_MESSAGES/
But when I load my page I still see the messages in English, not in spanish.

Do I miss something?

T.I.A


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]