Php gettext is not displaying the translated text (after generationg the .pot and .mo files with poEdit)

StackOverflow https://stackoverflow.com/questions/2261571

  •  20-09-2019
  •  | 
  •  

Question

I followed the folling tutorial: http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/

about Php gettext extension (I unchecked the comment in the php.ini)

The gettext is activated but it doesn't show up the translation (German).

Here are the files:

C:\wamp\www\php-test\test.php:

<?php
require_once("localization.php");
echo _("Hello World!");
?>

C:\wamp\www\php-test\localization.php:

<?php
$locale = "de_DE";
if (isSet($_GET["locale"])) $locale = $_GET["locale"];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./locale");
textdomain("messages");
?>

C:\wamp\www\php-test\locale\de_DE\LC_MESSAGES\messages.po:

msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-02-14 00:35+0800\n"
"PO-Revision-Date: 2010-02-14 00:37+0800\n"
"Last-Translator: Jano Chen <weedcl@hotmail.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-KeywordsList: _;gettext;gettext_noop\n"
"X-Poedit-Basepath: C:\\wamp\\www\\php-test\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: iso-8859-1\n"
"X-Poedit-SearchPath-0: .\n"

#: test.php:2
msgid "Hello World!"
msgstr "Hallo Welt!"

C:\wamp\www\php-test\locale\de_DE\LC_MESSAGES\messages.mo

(sorry from some reason I can't copy the text of this file)

alt text

When I open it should display "Hallo Welt" (Hello World in German) but instead it displays it in English (Hello World).

Any suggestions?

PS: I'm using Windows XP SP2

Was it helpful?

Solution

I was using Wamp Server 2 (i), I uninstalled it and used Wamp Server 2 (c), and it fixed the problem. Weird.

OTHER TIPS

as stated in the manual page for setlocale (did you read it?), windows uses different language/country/region strings. try adding them to your de_DE, like so (also from the man page):

setlocale(LC_ALL, 'de_DE', 'deu_deu');

see also the warning on locale information being maintained per process.

A bit basic, I know, but did you try to restart the web server? I have to do it everytime I update my .mo files.

Directory path provided for message catalog (second parameter of bindtextdomain function) should contain de_DE/LC_MESSAGES/ in this directory you have to copy your mo file.

All you need to do was restart Apache.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top