has an undiagnosed addiction to steamed pork buns
and works on webby stuff at Mozilla. more »

Getting text without gettext

Last week I made the switch from Windows to a Mac OS X. I’m definitely happy with the change, although one aspect gave me quite a bit of trouble: PHP gettext support. Now that AMO is localized (in 20 languages and growing!), gettext is required for a local installation.

To make a long story (involving MAMP, XAMPP, compiling PHP and Apache multiple times, and then back to MAMP again) short: MAMP should really include PHP compiled with gettext, as many other frustrated people have pointed out. During my battle, I asked others on the team that have been using Macs what they do for development. Some do all of their development in vim on a development server and others use a Linux virtual machine.

I had already written a basic .po string parser for the Localizer Control Panel, so I decided to make my own gettext emulator. The result is faketext, and MAMP + faketext = working Remora installation. It quickly parses .po files and will load a page in a specified language just as if you had the PHP extension installed.

Apparently there’s an inactive project called php-gettext that has the same idea but parses the binary .mo files instead. I didn’t try it because it would require many of the same modifications I made to work with AMO, and wenzel says it’s extremely slow anyway.

AMO faketext – save as config-local.php and drop in site/app/config.
Generic faketext – will probably require slight modification to detect the requested locale, as indicated in the comment at the top.

2 comments

Fred

Well done, Justin. It works very smoothly and is exceptionally easy to set up. Thumbs up.

Fred

Just wanted to mention that MAMP comes with gettext compiled in now. This is true for PHP5, I am unsure though if this is the case in its PHP4 instance also.

(this post is no longer accepting new comments)