Introduction: This is Php.ProgramThis section describes the related knowledge, skills, experience, and some PHP source code on the details page of internationalization (reprinted.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 344024 'rolling = 'no'>
PHP program internationalization here we mainly introduce the use of PHP extension gettext on the window platform to internationalize the program.
Step 1: Build the environment
1. First check whether the php_gettext.dll file exists in your PHP extension directory. If not, you need
Download one or copy one from other places and put it to the PHP extension directory.
2. Open PHP. ini, find "; Extension = php_gettext.dll", remove comments, and restart Apache.
Step 2: Principles
If you do not have an international programCode, Echo "hello"; and you need to write an international program
Echo gettext ("hello");, and then add the corresponding English "hi" in the configuration file ".
In this case, browsing in China will output "hello" on the screen, while browsing in the United States will output on the screen.
"Hi ". That is to say, what is displayed depends on your configuration file. If the configuration file cannot be found,
To output the content in the program.
Step 3: Coding Test
1. Create the file hi. php under D: \ www. The detailed code is as follows: 1 <? PHP
2
3 $ domain = 'test ';
4 bindtextdomain ($ domain, "locale/"); // you can specify the mo file path for a domain.
5 textdomain ($ domain); // set the domain from which the gettext () function locates the mo File
6 echo gettext ("Hi! "); // _ () Is the abbreviated form of the gettext () function.
7
8?>
Then you run the program change and only output "hi ". But we are Chinese, and we do not know "hi ",
We only know "hello", and the configuration file will be launched immediately. A tool is usually used to generate configuration files.
: Http://nchc.dl.sourceforge.net/sourceforge/gnuwin32/gettext-0.14.4.exe
After installation, you need to add "installation path/bin" to the system environment variable to use it in any directory.
Step 4: Create a configuration file
1. Assume that your tool has been installed and can be used in any directory. Run cmd now and
Switch the path to D: \ www, that is, the directory where hi. php is located.
Type xgettext-d hi. php -- from-code = gb2312, and then execute the command. Then, you can see a new
Hi. Po file. Note: -- from-code = gb2312, where gb2312 can also be UTF-8.
2. Open the hi. Po file and display it as follows: # Some descriptive title.
# Copyright (c) year the package's copyright holder
# This file is distributed under the same license as the package.
# First author <email @ address>, year.
#
#, Fuzzy
Msgid ""
Msgstr ""
"Project-ID-version: package version \ n"
"Report-msgid-Bugs-to: \ n"
"Pot-creation-Date: + 0800 \ n"
"Po-revision-Date: YEAR-MO-DA Ho: MI + Zone \ n"
"Last-TRANSLATOR: Full name <email @ address> \ n"
"Language-team: Language <LL@li.org> \ n"
& Quot; mime-version: 1.0 \ n & quot"
"Content-Type: text/plain; charset = charset \ n"
"Content-transfer-encoding: 8bit \ n"
#: Hi. php: 6
Msgid "Hi! "
Msgstr ""
Now there are two places to modify,
1: "Content-Type: text/plain; charset = charset \ n"
2: msgstr ""
Change charset in 1 to gb2312, and then change 2 to msgstr "hello ".
3. Type msgfmt-O hi.mo hi. Po and run the command to generate the hi.mo file.
Create the locale \ zh_cn \ lc_messages directory under D: \ www and copy hi.mo here.
4. Restart Apache and run it again. "Hello" can be output on the screen ".
Others:
If you use utft-8 encoding, you need to use
Bind_textdomain_codeset ($ domain, 'utf-8 ');
Replace charset in hi. Po with UTF-8, and save hi. Po as UTF-8,
Generate hi.mo again.
Summary:
We all hope that the programs we write can be widely used by the masses or even internationally, such as the well-known WordPress
It is also used internationally. Gettext is quite good and easy to use,
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/344024.html pageno: 5.
Here we will mainly introduce how to use the extended gettext of PHP in the window platform to internationalize the program.
Step 1: Build the environment
1. First check whether the php_gettext.dll file exists in your PHP extension directory. If not, you need
Download one or copy one from other places and put it to the PHP extension directory.
2. Open PHP. ini, find "; Extension = php_gettext.dll", remove comments, and restart Apache.
Step 2: Principles
If you do not have an international program with such code, Echo "hello"; while an international program needs to be written
Echo gettext ("hello");, and then add the corresponding English "hi" in the configuration file ".
In this case, browsing in China will output "hello" on the screen, while browsing in the United States will output on the screen.
"Hi ". That is to say, what is displayed depends on your configuration file. If the configuration file cannot be found,
To output the content in the program.
Step 3: Coding Test
1. Create the file hi. php under D: \ www. The detailed code is as follows: 1 <? PHP
2
3 $ domain = 'test ';
4 bindtextdomain ($ domain, "locale/"); // you can specify the mo file path for a domain.
5 textdomain ($ domain); // set the domain from which the gettext () function locates the mo File
6 echo gettext ("Hi! "); // _ () Is the abbreviated form of the gettext () function.
7
8?>
Then you run the program change and only output "hi ". But we are Chinese, and we do not know "hi ",
We only know "hello", and the configuration file will be launched immediately. A tool is usually used to generate configuration files.
: Http://nchc.dl.sourceforge.net/sourceforge/gnuwin32/gettext-0.14.4.exe
After installation, you need to add "installation path/bin" to the system environment variable to use it in any directory.
Step 4: Create a configuration file
1. Assume that your tool has been installed and can be used in any directory. Run cmd now and
Switch the path to D: \ www, that is, the directory where hi. php is located.
Type xgettext-d hi. php -- from-code = gb2312, and then execute the command. Then, you can see a new
Hi. Po file. Note: -- from-code = gb2312, where gb2312 can also be UTF-8.
2. Open the hi. Po file and display it as follows: # Some descriptive title.
# Copyright (c) year the package's copyright holder
# This file is distributed under the same license as the package.
# First author <email @ address>, year.
#
#, Fuzzy
Msgid ""
Msgstr ""
"Project-ID-version: package version \ n"
"Report-msgid-Bugs-to: \ n"
"Pot-creation-Date: + 0800 \ n"
"Po-revision-Date: YEAR-MO-DA Ho: MI + Zone \ n"
"Last-TRANSLATOR: Full name <email @ address> \ n"
"Language-team: Language <LL@li.org> \ n"
& Quot; mime-version: 1.0 \ n & quot"
"Content-Type: text/plain; charset = charset \ n"
"Content-transfer-encoding: 8bit \ n"
#: Hi. php: 6
Msgid "Hi! "
Msgstr ""
Now there are two places to modify,
1: "Content-Type: text/plain; charset = charset \ n"
2: msgstr ""
Change charset in 1 to gb2312, and then change 2 to msgstr "hello ".
3. Type msgfmt-O hi.mo hi. Po and run the command to generate the hi.mo file.
Create the locale \ zh_cn \ lc_messages directory under D: \ www and copy hi.mo here.
4. Restart Apache and run it again. "Hello" can be output on the screen ".
Others:
If you use utft-8 encoding, you need to use
Bind_textdomain_codeset ($ domain, 'utf-8 ');
Replace charset in hi. Po with UTF-8, and save hi. Po as UTF-8,
Generate hi.mo again.
conclusion:
we all hope that the program we write can be widely used by the masses or even internationally, like the famous WordPress.
it is also used internationally. Gettext is very good and easy to use.