I developed a rather large and extensive PHP application for maintaining 
a news publishing site. All static text was, when I created it, written 
in English. Form field labels, long explanatory texts, navigational 
links, everything. The popularity of the application, however, has 
drifted outside the Anglo boundaries, and now I need to internationalize 
the code to support other languages for text output and date formatting. 
(Localization I'll leave up to those better qualified). I'm looking for 
feedback on various methods of allowing easy localization.

The date formatting stuff is easy enough with built-in PHP functions. 
All my dates are instantiated as objects anyway, so output format is 
nicely encapsulated in class methods, making that part easy.

The manner of supporting localization of text strings, however, allows 
for a few more options. I've taken note of how a few different PHP apps 
have broached the topic:

-- phpMyAdmin. Minimal static text. Loads a localized text file 
containing localized variable assignments, and always puts out text by 
variable reference rather than hard-coded text.

-- FUDforum2. Fairly large quantity of text. Also uses a text file of 
variables and their localized value, but seems to have a more indirect 
manner of putting out the variable-based text. (Part of the apparent 
"indirection" is that perusing the code reveals TONS of hard-coded 
English phrases that don't seem to be localized. But I haven't actually 
seen, as a web user, the FUDforum2 operating in a non-English language, 
so I can't really vouch for whether all the text is internationalized or 
not).

-- The PHP Manual speaks highly of gettext() calls, relying on a 
standard, mature UNIX function to automatically handle 
internationalization. It sounded good, and I liked the idea of it 
leveraging the power of something that was _designed_ for 
internationalization, and not a "good hack job of variable 
substitutions" attempting the same functionality.

So I've begun the process of modifying all of my text output from

echo ("My English phrase dangles");
to
echo _("My English phrase dangles");

and the like. It's beautiful. 3 extra characters -- "_()" -- to wrap 
around strings, and poof! it's 90% of the way towards the United Nations.

I created a quick English string file of a few webpages worth of text, 
threw together a rough French translation, and tried viewing the site in 
French. Seemed to work wonderfully.

So, this far, I'm happy, and continuing to modify the code to 
internationalize the output. I'm only a bit wary, however, because it 
seems relatively easy, yet I haven't run into any PHP applications that 
have internationalized their interface in this way. (That doesn't mean 
there aren't any out there, but I haven't run into them). Are there any 
potential problems that I need to be aware of? Substantial performance 
hits? Bogeymen?

I'd love to hear success stories from anyone using gettext() with a 
substantial number of strings (like 500-1000).

Cheers,
spud.

-------------------------------------------------------------------
a.h.s. boy
spud(at)nothingness.org            "as yes is to if,love is to yes"
http://www.nothingness.org/
PGP Fingerprint: 7B5B 2E7A FA96 865A D9D9  5D6D 54CD D2C1 3429 56B4
-------------------------------------------------------------------


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to