类别:编程语言 点击:0 评论:0 推荐:


With the upgrade of PHP to version 4.1.1 a new feature was introduced; gettext. Here's a small write-up about how to use gettext on your site.

So, what is gettext and how do I use it?
PHP's gettext functions provide an interface to the GNU gettext utility, which is a utility for programmers to internationalize their programs. Gettext helps manage the messages output by the software. You can also use it for internationalization (often abbreviated to I18N) of your website using PHP.

The basic usage in your PHP script is fairly simple;
1. set the language to be used
2. echo/print your text as you normally would, prepending 'gettext' or an underscore '_'. So instead of 'echo "Hello World"', you would write 'echo _("Hello World")' or 'echo gettext("Hello World")'

The translations are stored in a compressed binary file (.mo files), which you create from the plain ASCII files created by gettext from your script (.po files).

So, step by step, how to create your script.
Let's assume the script you want to internationalize looks like this: