views:

249

answers:

2

Which is the best way of implementing a language translation for mutli -lang site. I have two methods, i.e.

1) Just put all the static text contents in the pages to database ie a database driven programing style

$translation('register_form');
<form >
 <input name="search" >
</form>

some sort of transltion.

2) is in like wordpress .mo files method.

I want to know more about that kind of translation , how it works with .mo like files...

or any other better way to make a translation module.

+1  A: 

For .mo file support, check out the gettext functions, and look at the original GNU gettext documentation.

In a nutshell, anytime you use natural language, you wrap in a call to _() (an alias for gettext)

echo _("Hello world");

Once all your sources are doing this, run the GNU Xgettext tool to build a .pot file, which forms the "template" for your language translations. For each desired language, you'd merge this .pot file into an individual .po file for each language. The merge operation, again provided by xgettext, ensures you update the file with new strings, without losing any existing translations.

These .po files get sent to your translators, who might use a tool like poedit to provide the translation. When the .po file comes back, you can generate the binary .mo file which is used by gettext.

There are also classes in the Zend Framework which provide more facilities beyond this too, e.g. more file formats, and detection and selection of user preferred language in HTTP headers.

Paul Dixon
A: 

Look into gettext - it's not the perfect solution to everyone's problem, but it might be for yours.

Shep