note 16835 modified in ref.gettext by thomasgm
| From: | thomasgm@php.net | Date: | Sat, 29 Mar 2003 18:34:57 +0000 |
| Subject: | note 16835 modified in ref.gettext by thomasgm | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-45985@lists.php.net to get a copy of this message | ||
I had alot of problems to get gettext() to work on my windows2000-php webserver. The following will
give those windows-php users something to hold on to:
Note the way you have to use slashes for the bindtextdomain command:
For a 'greetings' domain:
bindtextdomain ("greetings", ".\includes\translations");
(so, TWO slashes instead of one between the folder-names!)
ALSO, I had to change the filename to be 'greetings.mo': This was NOT clear from all the
gnu-pages I read. I had named those files: nl.mo (for dutch) and fr.mo (for french etcetera).
I provide my code and folder-structure here for other windows-users:
<?
Header("Content-type: text/plain");
// Bind a domain to directory
// Gettext uses domains to know what directories to
// search for translations to messages passed to gettext
bindtextdomain ("greetings", "./includes/translations"); // Set the current
domain that gettext will use
textdomain ('greetings'); # Make an array
# Use the ISO two-letter codes as keys
# Use the language names as values
$iso_codes = array (
'en'=>'English',
'fr'=>'French',
'it'=>'Italian',
'pt'=>'Portuguese',
'es'=>'Spanish',
'nl'=>'Nederlands'
);
foreach ($iso_codes as $iso_code => $language) {
# Set the LANGUAGE environment variable to the desired language
putenv ('LANG='.$iso_code); # Print out the language name and greeting
# Filter the greeting through gettext
printf ("%12s: %s\n", $language, gettext("str_hello")) & "\n";
}
?>
In the windows-webfolder I have the following directory-structure:
==
includes\translations
includes\translationsen
includes\translations\en\LC_MESSAGES
includes\translations\en\LC_MESSAGES\greetings.po
includes\translations\nl\
includes\translations\nl\LC_MESSAGES
includes\translations\nl\LC_MESSAGES\greetings.mo
\includes\translations\nl\LC_MESSAGES\greetings.po
===
To get this working you will need a greetings.po file like this:
(this one is in the 'nl' subdir for dutch language):
===
msgid ""
msgstr ""
"Project-Id-Version: n"
"POT-Creation-Date: n"
"PO-Revision-Date: 2001-11-14 17:11+0100n"
"Last-Translator: Melle Koning <hace_x@yahoo.com>n"
"Language-Team: <>n"
"MIME-Version: 1.0n"
"Content-Type: text/plain; charset=utf-8n"
"Content-Transfer-Encoding: 8bitn"
msgid "str_hello"
msgstr "hallo"
===
and you have to 'compile' this .po file to a .mo file with the following command-line (go
to windows 'command prompt'):
==
msgfmt -o greetings.mo greetings.po
==
To get msgfmt working on your windows machine, you will need to have libiconv.dll, libintl.dll and
msgfmt.exe in your path. What I did was put these three files in a new c:utils folder and than run
the command:
path=%path%;c:utils
I hope this helps some windows-users like me to get gettext() to work on their systems.......
Cheers,
Melle
hace_x@yahoo.com
--was--
I had alot of problems to get gettext() to work on my windows2000-php webserver. The following will
give those windows-php users something to hold on to:
Note the way you have to use slashes for the bindtextdomain command:
For a 'greetings' domain:
bindtextdomain ("greetings", ".\includes\translations");
(so, TWO slashes instead of one between the folder-names!)
ALSO, I had to change the filename to be 'greetings.mo': This was NOT clear from all the
gnu-pages I read. I had named those files: nl.mo (for dutch) and fr.mo (for french etcetera).
I provide my code and folder-structure here for other windows-users:
<?
Header("Content-type: text/plain");
// Bind a domain to directory
// Gettext uses domains to know what directories to
// search for translations to messages passed to gettext
bindtextdomain ("greetings", "./includes/translations"); // Set the current
domain that gettext will use
textdomain ('greetings'); # Make an array
# Use the ISO two-letter codes as keys
# Use the language names as values
$iso_codes = array (
'en'=>'English',
'fr'=>'French',
'it'=>'Italian',
'pt'=>'Portuguese',
'es'=>'Spanish',
'nl'=>'Nederlands'
);
foreach ($iso_codes as $iso_code => $language) {
# Set the LANGUAGE environment variable to the desired language
putenv ('LANG='.$iso_code); # Print out the language name and greeting
# Filter the greeting through gettext
printf ("%12s: %s\n", $language, gettext("str_hello")) & "\n";
}
?>
In the windows-webfolder I have the following directory-structure:
==
includes\translations
includes\translationsen
includes\translations\en\LC_MESSAGES
includes\translations\en\LC_MESSAGES\greetings.po
includes\translations\nl\
includes\translations\nl\LC_MESSAGES
includes\translations\nl\LC_MESSAGES\greetings.mo
\includes\translations\nl\LC_MESSAGES\greetings.po
===
To get this working you will need a greetings.po file like this:
(this one is in the 'nl' subdir for dutch language):
===
msgid ""
msgstr ""
"Project-Id-Version: n"
"POT-Creation-Date: n"
"PO-Revision-Date: 2001-11-14 17:11+0100n"
"Last-Translator: Melle Koning <hace_x@yahoo.com>n"
"Language-Team: <>n"
"MIME-Version: 1.0n"
"Content-Type: text/plain; charset=utf-8n"
"Content-Transfer-Encoding: 8bitn"
msgid "str_hello"
msgstr "hallo"
===
and you have to 'compile' this .po file to a .mo file with the following command-line (go
to windows 'command prompt'):
==
msgfmt -o greetings.mo greetings.po
==
To get msgfmt working on your windows machine, you will need to have libiconv.dll, libintl.dll and
msgfmt.exe in your path. What I did was put these three files in a new c:utils folder and than run
the command:
path=%path%;c:utils
I hope this helps some windows-users like me to get gettext() to work on their systems.......
Cheers,
Melle
hace_x@yahoo.com
http://www.php.net/manual/en/ref.gettext.php