Tuesday, August 4, 2009

Modest success with translations

I have convinced gettext() to work with my web pages!

At least in my development environment. The development environment is SuSE 11.1; my production web server runs on Ubuntu 8.10. I'll have to check the production environment and make sure that it has support for the expected locales.

Gettext is very picky about the locale specification. I was using 'fr' for my locale... since that was listed in the example. But that text does not match any of the available locales on my computer. Since gettext() found no exact match, it fell back to the default message, which is the ID you provided. Instead of 'fr' I must specify 'fr_FR' for the locale. (And 'UTF-8' for the encoding.)

Solving this problem took longer than I expected. (Problems often do.) I learned a few other things about PHP while I was struggling with this problem:

1) Debugging PHP is difficult. Or maybe I need to learn more debugging skills for PHP.

2) Using PHP in script mode is a quick way to test files. It's much easier than editing a file, FTP'ing it to the server, moving it to the proper directory, and then calling up the web page.

3) I can use better search techniques for documentation on the web. My initial searches kept pointing me to the PHP documentation. The GNU documentation (although lengthy) had the information that I needed.

4) I can use more patience reading long documents.

5) Sometimes one has to think, run  tests, think again, and run more tests. Thinking alone does not solve the problem, nor does running random tests.

No comments:

Post a Comment