tags:

views:

543

answers:

2

I have an PHP application that I want localized. Currently, the way I'm doing this is a very ugly way: $loc['hello'] = "Hello", echo $loc['hello']; will show Hello, and you can change the file to change the language. What I want is a better way and a faster of doing this, what I'm considering:

  • 1 XML file with language data for all page (will it be slow as every page will load the language data for the entire site)
  • Multiple files, one xml file for each page (not much help as it is just as messy as the old system)
  • gettext() (This seem to be the best way, but I only discovered it today, so will it be hard to change from my current system to this? Is it fast?)

So to summarize, which way is the fastest, the cleanest, and the easiest to move from my current way to the new one. Thanks.

+3  A: 

Similar Questions:

Here's a benchmark comparing gettext with string-array: Benchmarking PHP Localization - Is gettext fast enough?

Aziz
Thanks for the quick reply! But one of the thing I want to know is how slow would it be to let's say load a XML of 100 localization data when only 10 is required for the page. Does the XML parser read the whole file to memory? or does it look for the key you want.
Yifan
I added a link for a benchmark test that compares gettext with other approaches.
Aziz
If you're going to use XML, most probably the parser will read the whole file in order to allow search\access.
Aziz
Ok, thanks, and for anyone who's wondering, I've decided to stick with my current system with a few modifications (all language data is in one file, but it only loads the required strings). And users can import an XML file which generates a PHP file (for people who don't know PHP and want to transl
Yifan
well, I personally would go with gettext only if the project is large enough (i.e. worth the trouble). For small project or scripts, I would use something like string array or XML file.
Aziz
A: 

A PHP array like the one you already have is pretty fast and clean in my opinion.

Localization itself is ugly to code and manage changes so don't expect that there is a method to make all the pain go away.

Shard