can't get gettext() to work!
| From: | Colin Viebrock | Date: | Thu, 02 Aug 2001 18:04:18 +0000 |
| Subject: | can't get gettext() to work! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-60977@lists.php.net to get a copy of this message | ||
(I posted this on php.i18n, but I'm hoping that the bigger audience here
might get me an answer sooner).
Okay, here is what I've done:
I have a file /www/test.php:
<?
putenv('LANG=en');
setlocale(LC_ALL, '');
bindtextdomain("messages", "./locale");
textdomain("messages");
echo _("Hello world.");
?>
I then do:
xgettext --keyword=_ -C /www/test.php
This makes "messages.po" which looks like:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Free Software Foundation, Inc.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2001-08-01 17:13-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: /www/test.php:9
msgid "Hello world."
msgstr ""
I then do:
mkdir /www/locale/fr
mkdir /www/locale/fr/LC_MESSAGES
cp messages.po /www/locale/fr/LC_MESSAGES
I then edit that messages.po so it reads:
msgid "Hello world."
msgstr "Bonjour monde."
Then:
msgfmt /www/locale/fr/LC_MESSAGES/messages.po -o
/www/locale/fr/LC_MESSAGES/messages.mo
I then check the test.php file in a browser: it's in english.
I edit test.php to read:
<?
putenv('LANG=fr'); /* <<< changed here */
setlocale(LC_ALL, '');
bindtextdomain("messages", "./locale");
textdomain("messages");
echo _("Hello world.");
?>
Reload in a browser, and it's still english. What am I missing?!?!
- Colin