Best system for multiple language support in PHP?

2019-05-28 19:51发布

问题:

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.

回答1:

Similar Questions:

  • what is the best method to build “multilingual” script in php?
  • Programming Multi-Language PHP applications

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



回答2:

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.



标签: php xml gettext