Usually people write the program, it is written in the program, such as: echo "Hello World!"; If you want to change into its language, write an internationalization process, you must open it one by one, and the program is short. OK, if the program has 10,000 or even more, it is not so easy to change it. Recently, with the gradual standardization of I18n, I also talk about how to achieve international support in PHP. Like other programs, PHP can also use the GetText Suite Writing I18N program to implement NLS (Native Language Support) International Support, please refer to the official document (http://www.gnu.org/Manual/gettext/index. HTML). Realization: The program designer writes the information to be displayed in the program code. When the program does not directly display the information written by the programming designer, it will look for an information file that set up the language. If not found, the information in the display code will be displayed. First, install setting GetText Suite: 1) * NIX System: 1, from http://www.gnu.org/software/gettext/gettext.html to download GetText Package, install 2, compile PHP, plus " With-gettext [= dir] ", where DIR is the directory installed with the GetText, the default is: / usr / local 3, saved, then Restart Server. 2) Win32 system: 1, you need to copy the GNU_Gettext.dll file to the system directory (EX: C: / Winnt / System32 or C: / Windows / System32), the file named libintl-1.DLL after PHP 4.2.3, It can be obtained under PHP4 / DLLs. 2, open the php.ini file, look up extension = php_gettext.dll, remove the front ";" 3, save, then restart Server. If everything goes well, you can see GetText words in phpinfo (), which has been set up. Second, there are several functions in the php_gettext.dll kit, please see the relevant manual. Here we only remember 3 functions, as follows:
String BindtextDomain (String Domain, String Directory) String Text_Domain String GetText (String Message)
Third, writing I18n program:
PHP // General Program Echo "Hello World!");?>
Below is the I18N program: hello.php
php // i18n program example starts define ('package', 'hello'); // Defines the name of the MO file you want to use, usually, we all have the same name definition and program name as Package. Putenv ('lang = zh_tw'); setLocale (lc_all, 'zh_tw'); // Specify the language you want to use, such as: en_us, zh_cn, zh_tw bindtextdomain (package, '/ apache / htdocs / locale'); TextDomain ); // ///Apache/htdocs/locale/En/LC_MESSAGES/HELLO.MO Echo GetText ("Hello World!");?>>
Enter: http://localhost/hello.php, the output is: "Hello World!" NOTE: Follow the habits of GNU Package, you can use _ (...) instead of getText (...), This will make a lot of GetText. Fourth, then set the GetText PO file: 1. Create a directory structure, as shown below: bindtextdomain's dir / language / lc_messages domain.po domain.mo where the directory used by bindtextDomain (), Langguage is the language, Domain For the Package name. Take the above as an example: / local / zh_tw / lc_messages Hello.po Hello.mo 2, create a PO file XGettext -d [What is the defined package name] [Program File Name] The following XGettext below, the MSGFMT file file can be (http: //switch.dl.sourceForge.Net/SourceForge/gnuwin32/gettext-0.10.40-bin.zip) Download, need libiconv.dll, libintl.dll support. Take the above hello.php file as an example, $ XGettext -d Hello Hello.php will generate a Hello.po file, the content is as follows: # Some Descriptive Title. # Copyright © Year Free Software Foundation, Inc. # Firsthor