R – How to implement a language translation module in php


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

<form >
 <input name="search" >

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.

Best Solution

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.

Related Question