Tutorial: Localizing PHP Applications the Right Way, with gettext
Join the DZone community and get the full member experience.
Join For FreeEnglish has become the default language of software development for economic and historical reasons. But maintaining only English-language code is not ideal, because plenty of developers' first language isn't English; and maintaining multiple codebases, in different languages, is, like every code-multiplication, an easy recipe for disaster.
The gettext utilities offer a workaround -- but implementation isn't always obvious. (The full documentation is quite thorough, but rather long.) The continuing popularity of PHP makes gettext particularly useful for PHP developers -- but the php.net documentation is pretty terse, and barely addresses Windows (where PHP is growing rapidly).
The solution? Abdullah Abouzekry's step-by-step guide to localizing PHP, recently posted on phpmaster.com.
As Abdullah explains:
In this series of articles you will learn how to gettext to localize your PHP application. Part 1 will provide just a quick foray into gettext. Each subsequent part will build on preceding parts, teaching you how to handle multiple translation domains, plural forms, and even how you can automate some of the localization process.
One of the neat things about this walkthrough is its attention to detail: in 'Preparing the Environment', for example, Abdullah includes special instructions for Windows and Linux users, something the php.net documentation left out (resulting in a small patchwork of anonymously contributed notes).
Only Part 1 is up so far. But check it out and, if it helps you, stay tuned for additions in the future.
Opinions expressed by DZone contributors are their own.
Comments