Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP gettext on Windows

There are some tutorials out there for gettext (with Poedit)... unfortunately, it's mostly for a UNIX environment. And even more unfortunate is that I am running my WAMP server on Windows XP (but I am developing for a UNIX environment) and none of the tutorials can get gettext working properly for me. From the manual page, it appears that it's a different process on a Windows environment. I've tried out some of the solutions in the comments but I still can't get it to work! I've spent many hours on this, hopefully someone can point me in the right direction to get this thing to work! (And I'm sure there are others out there who share my frustration.) So far with my setup, I'm only getting output "Hello World!" whereas I should be getting the translated string.

Here is my setup/code so far:

// test.php
if (!defined('LC_MESSAGES')) {
    define('LC_MESSAGES', 6);
}

$locale = "deu_DEU"; // apparently the locales are different on a WINDOWS platform

putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("greetings", ".\locale");
textdomain("greetings");

echo _("Hello World"); 

Folder structure

root:     C:\Program Files\WampServer 2\www
test.php: C:\Program Files\WampServer 2\www\site
.po:      C:\Program Files\WampServer 2\www\site\locale\deu_DEU\LC_MESSAGES\greetings.po
.mo:      C:\Program Files\WampServer 2\www\site\locale\deu_DEU\LC_MESSAGES\greetings.mo
like image 918
axsuul Avatar asked Sep 24 '09 17:09

axsuul


2 Answers

I ran into problems while working with gettext on my local machine, and after some search i found this page which solved my problem: http://www.kipras.com/blog/getting-gettext-to-work-in-apache-on-windows/96

I am quoting from the web page:

On Linux servers (or any other servers apart windows), the way to do it is this:

setlocale(LC_MESSAGES, “en_US”);

The correct way to set locality on windows is this:

putenv(“LC_ALL=en_US”);
like image 67
wesamly Avatar answered Oct 16 '22 20:10

wesamly


I had the same problem, and wasted almost a day or so on it. Finally, I found a very simple solution, namely to uninstall WAMP Server (version 2.1), and install a newer version (WampServer 2.1e - 32 bits). It's strange, but it solved the problem completely.

Here is the sample code that worked for me:

<?php

    $locale = "deu_DEU";

    putenv("LC_ALL=$locale");
    setlocale(LC_ALL, $locale);

    bindtextdomain("greetings", "./locale");
    textdomain("greetings");

    echo _("Hello World");

?>

Hope it helps.

like image 26
Hamid Avatar answered Oct 16 '22 20:10

Hamid