Internationalization in PHP (in Windows)

I have been working on a web site, written in PHP, that will need a translation. In programming, this is Internationalization, or I18N. I could easily write something that would check for the language variable and provide the alternate translation, but I wanted to do it correctly.

Yeah, I know, silly me, wanting to do something a little more complicated and using Windows for the development machine.

I decided to use gettext, because it seemed easy and it’s what WordPress uses, so I’d be more familiar with it when I get to it on a blog.

After fighting with it for a while and doing everything right but getting no results, I uploaded it to the server to test it out… and it worked perfectly.

The problem is that gettext doesn’t work in Windows. Sure, it seems to work, but setting the localization doesn’t work and there doesn’t seem to be any alternative way to set the localization to make use of the translations… so no way to actually see the translated text while in development in Windows. And I want to see it working.

I spent hours over two days searching the Internet for answers. So many answers… none ever worked.

Until I found this page: http://www.extradrm.com/blog/?p=1035

Thank you nameless person for finally providing a correct answer. And the correct answer is that the setlocale function of PHP does not work in Windows. Period.

But thanks to Danilo Segan, there is an alternate version of gettext that actually works in Windows, and that’s over here (https://launchpad.net/php-gettext/+download).

Now I can move forward with programming the project.

And I’m putting this blog post out here so that maybe the next person who goes searching all over the Internet for a solution will find this post and not waste as much time as me trying every which type of code and finding that none of them works.

Leave a Reply

Your email address will not be published. Required fields are marked *