Step One: Build the environment
1, first check your PHP extension directory if there is php_gettext.dll this file, if not, this will require you
Download one or copy it from somewhere else and put it in the PHP extensions directory.
2, open php.ini, look for "; Extension=php_gettext.dll", then remove the comment and restart Apache.
Step Two: Principle explanation
If you do not have the internationalization of the program has such code, echo "Hello", and the internationalization of the program you have to write
echo gettext ("Hello"), and then add "Hello" in the configuration file corresponding to the English "HI".
At this point, Chinese browsing will output "Hello" on the screen, while the US area will output on the screen
"Hi". That is, the final display of what is based on your profile, if the configuration file cannot be found,
To output the contents of the program.
Step Three: Coding Test
1, we create a new file under D:\www hi.php, the detailed code is as follows
Copy CodeThe code is as follows:
$domain = ' Test ';
Bindtextdomain ($domain, "locale/");//Set the MO file path for a domain
Textdomain ($domain);//set GetText () function from which domain to find MO file
Echo gettext ("hi!"); /_ () is a shorthand form of the gettext () function
?>
When you run the change program, only the "Hi" will be output. But we are Chinese, we do not know "Hi",
We only know "Hello", then you need to configure the file. The configuration file is generated in general with a tool.
Download Address: Http://nchc.dl.sourceforge.net/sourceforge/gnuwin32/gettext-0.14.4.exe
After installation, in order to use in any directory, you need to add "installation path/bin" to the system environment variables.
Step Four: Configuration file generation
1, we assume that your tool is already installed and can be used in any directory. Now it's time to run CMD and put
The path switches to d:\www, which is the directory where hi.php resides.
Type xgettext-d hi hi.php--from-code=gb2312, and then execute, and you can see the freshmen into a
Hi.po file, note:--from-code=gb2312, where gb2312 can also be utf-8.
2. Open the Hi.po file, which appears as follows:
Copy CodeThe code is as follows:
# SOME Descriptive TITLE.
# Copyright (C) year the package ' S copyright HOLDER
# This file was distributed under the same license as the package.
# First AUTHOR , year.
#
#, Fuzzy
MsgId ""
Msgstr ""
"Project-id-version:package version\n"
"Report-msgid-bugs-to: \ n"
"Pot-creation-date:2009-01-19 17:47+0800\n"
"Po-revision-date:year-mo-da ho:mi+zone\n"
"Last-translator:full NAME \ n "
"Language-team:language \ n "
"Mime-version:1.0\n"
"Content-type:text/plain; Charset=charset\n "
"Content-transfer-encoding:8bit\n"
#: Hi.php:6
MsgId "hi!"
Msgstr ""
Now there are two places to change,
1: "Content-type:text/plain; Charset=charset\n "
2:msgstr ""
Change the charset in 1 to gb2312, then change the 2 to Msgstr "Hello".
3, type Msgfmt-o hi.mo hi.po, execute, then generate Hi.mo file.
Then create a new locale\zh_cn\lc_messages directory under the d:\www and copy the Hi.mo here.
4, now restart Apache, run again, the screen can output "hello."
Other:
If you use UTFT-8 encoding, you need to use
Bind_textdomain_codeset ($domain, ' UTF-8 ');
corresponding to the HI.PO in the charset to change to Utf-8, but also need to save Hi.po to Utf-8 format,
Just generate the Hi.mo again.
Summarize:
We all hope that the program we write can be widely used by the public and even internationally, like the famous WordPress
He is also the international use. GetText is also very good, easy to use,
http://www.bkjia.com/PHPjc/324154.html www.bkjia.com true http://www.bkjia.com/PHPjc/324154.html techarticle Step One: Set up the environment 1, first check your PHP extension directory to see if there is php_gettext.dll this file, if not, it will require you to download one or copy from other places, ...