Search code examples
phplocalizationinternationalizationmultilingualgettext

Whats the best & fastest method to support multi language in PHP Application


Though there are lot of similar questions already asked here, I didn't find the answer i was looking for..

What's the best way to develop multi-language application, It should be very fast.. and i don't know how much text i will translate.

Method 1: create and keep all the text in an array for every language i want to support and include that file everywhere.

Method 2: Use gettext (.MO, .PO files)

Method 3: Store all the translations in a text file and write a function to go through all the text and when matched display its value

Method 4: Store all the text and its translations in database, But i don't think it will be faster than storage in Filesystem.

Method 5: Same as method 1 but i will create multiple files per language just to keep everything structured.

Though all of these will work, Which do you guys think will be the fastest method and do let me know if i missed any method.


Solution

  • This is a complicated problem and its not always as obvious as you might think. You may in some cases, with right to left languages or particular cultural reasons, need to develop separate layouts for a particular region.

    Regardless of which method you choose, you will want to cache all of or parts of your pages and use a cached version if available before regenerating the page again.

    I would probably avoid 3 and 4. You don't want to be reading from the disk more than you have to. If you can cache translation arrays in memcached, you can save yourself disk access in loading translation tables.