Monday, 7 May 2007
Tutorial on gettext for Internationalization of PHP Applications |
| |
|
| |
A new post over at the Northclick blog provides a tutorial for those who want to optimize the internationalization of their PHP applications.
The author starts the tutorial by giving some reasons of using gettext:
- Defacto-standard for i18n of Unix systems and their applications
- Very fast, because it uses a binary format and native caching
- No database required, get the load out of it
- You can put the translation files within your version-control many editors for every platform. -> easy for external translators
- Powerful command line tools for special needs
- Stable
After this the disadvantages follows:
- Not thread-safe
- You have to spend some time to get it work
- Debugging
gettext can be hard in PHP - Restart of web server needed to activate new translations (not in CGI version).<.
The author also gives some basic understanding points like the following:
- Translated sentences will seem like function in PHP
xgettext is a command line tool and will walk through your source code to find every string which should be translated. xgettext will recognize the translations by the function names.- there are three file types that you must know:<:
- pot - this is the template for the translation
- po - this is a single translation for each language (it is generated from the pot file)
- mo - this is the “compiled” binary database for the application (generated from the po file)
He explains the rest of the tutorial under the following steps:
- First step: Generate Functions and init gettext
- Second step: Translate your Application
- Third step: Generate a pot file (Template)
- Fourth step: Generate your PO Files from your POT Template and translate
- Last step: Generate Binaries
The author also adds some tips and tricks for debugging. |
| |
|
Read the Post
|
| |
|
|
| |
|
|
| |
|