NYCPHP Meetup

NYPHP.org

[nycphp-talk] Reading in strings from text file

John Campbell jcampbell1 at gmail.com
Mon Dec 10 14:23:31 EST 2007


> I am about to start on a module for i18n and wonder if anyone has experience
> on how long it takes to read in let's say 1,000 strings of about 30 characters
> on average from a text file that has numeric keys, with those keys  becoming
> the key of an array that in the end is to be stored in $_SESSION. Is there a
> better place than $_SESSION to hold this? What I really want to prevent is to
> have each script that generates text output have to read in its own strings as
> this adds management needs to make sure the right strings are picked up.
> Anyone knows how well this would scale with 10,000 or 100,000 strings? Sure, I
> could try it out, but asking NYPHP is way faster.

I highly recommend *not* doing it this way.
1) A session is the worst place to put the data because there is a
different session file for each user.  If you do want to do this, use
a singleton pattern to access the array bundle.
2) Plurals, and translation re-ordering will be nearly impossible.
3) Performance will be suboptimal.
4) You will have to build your own tools for the translators.
5) Dealing with merges is going to be a pain.
6) You need to give the translators context for the strings.
7) Your system will have to deal with non-translated strings appropriately.

The good news is that all of these problems associated with i18n, have
been solved.  Gettext is the GNU standard and you get all of the tools
for free (PoEdit for translators, msgmerge, binary encoding for
performance)  Gettext seems confusing and complicated at first, but
you will appreciate it once you have tried something else.

I know this doesn't answer your question about the performance, but it
is unlikely that you will be able to successfully internationalize an
application with 1000+ strings if your plan is to use array bundles.

Just so you understand the difficulty of i18n'ing an app, consider this string:
"Your Visa card with last four digits 1234 expires on Dec 15, 2007".

In another language, it may need to be written as:
"On 15:Drb:2007, expires, last 4 digits 1234, is your Visa"


Also, your application code will become unreadable if you use array
bundles. Consider:
echo $translation_bundle[ERR::CC_EXP];
vs the gettext way:
echo _("Your credit card has expired");

I find the latter much more readable.

Cheers,
John Campbell



More information about the talk mailing list