Using GetText to implement the internationalization programming of PHP

Source: Internet
Author: User
Tags manual gettext i18n

Usually when people write programs, they write words that die in the program, such as: echo "Hello world!"; , if you want to change to the language of the country, write the internationalization of the program, it is necessary to open one by one to modify, the procedure is relatively short, if the program has tens of thousands or more, it is not so easy to change. Recently, with the gradual standardization of i18n, I also talk about how to achieve internationalization support in PHP. As with other programming languages, you can also use the GetText suite to write i18n programs in PHP to implement the NLS (Native Language Support) internationalization support, please refer to the official documentation (Http://www.gnu.org/manual/get text/index.html).

Implementation process: The Program designer writes the information to be displayed in the code, does not directly display the information that the programmer writes when running the program, but first goes to find a set of information file of the language family. If it is not found, the information in the code is displayed.

Installation Set GetText Kit:

1) *nix System:

1, from the http://www.gnu.org/software/gettext/gettext.html download GetText package, to install

2, compile PHP when adding "--with-gettext[=dir]", where DIR for GetText installed

Directory, defaults to:/usr/local

3, save, and then restart server.

2) WIN32 System:

1, need to copy the Gnu_gettext.dll file to the system directory (Ex:c:\winnt\system32 or C:\WINDOWS\SYSTEM32), PHP 4.2.3 file name after Libintl-1.dll, can be in the php4\ DLLs under the access.

2, open php.ini file, find Extension=php_gettext.dll, remove the front of the ";"

3, save, and then restart server.

If all goes well, you can see the word gettext in Phpinfo (), which is now set.

Second, the Php_gettext.dll kit has several functions, specifically see the relevant manual. Here we can just memorize 3 functions, as follows:

String Bindtextdomain (string domain, string directory)

String Textdomain (String text_domain)

String GetText (String message)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.