First, the use of GetText, because Smarty have the corresponding GetText plug-in, so directly with the plug-in
The steps are as follows:
1.1 Add the following code to the common include file:
$domain _info[' Lang '] is the language set value for the cookie $language_code = $domain _info[' lang '];//interface language set to Chinese if ($language _code = = ' Zh_ CN ') {//Set Target language putenv ("lang= $language _code") setlocale (Lc_all, $language _code);//$package for mo file name $package = ' I18n_ ZH ';//bind mo file path Bindtextdomain ($package, '/var/locale ');//Set the file name of the mo file to be searched Textdomain ($package);
Specifies the encoding bind_textdomain_codeset ($package, ' UTF-8 ') of the Mo file returned to GetText;} ElseIf ($language _code = = ' BIG5 ') {//interface language set to traditional $language_code = ' zh_tw ';p utenv ("lang= $language _code"); SetLocale (lc_ All, $language _code); $package = ' i18n_tw '; Bindtextdomain ($package, '/var/locale '); Textdomain ($package); bind_ Textdomain_codeset ($package, ' UTF-8 ');} else{//interface Language is English//Set Target language putenv ("lang= $language _code"); setlocale (Lc_all, $language _code);//$package The name of MO file $ Package = ' i18n_en ';//bind mo file path Bindtextdomain ($package, '/var/locale ');//Set the file name of the mo file to be searched Textdomain ($package);// Specifies the encoding bind_textdomain_codeset ($package, ' UTF-8 ') of the Mo file returned to GetText;} Add the processing end of the internationalized language ***************/
|
1.2 Add the T tag required by the Smarty plugin in the corresponding template
1.3 Generating C files with the tools provided by the Smarty plugin
This c file is to extract all the tags in the template.
Php-q./tsmarty2c.php *.html $package. C |
Note: The default C file name is the best as defined in 1.1
Note that the open tag and close tag of the smarty defined in tsmarty2c.php must be consistent with the Smarty configuration file settings
1.4 Calling the Linux system Xgettext to generate a file with the C file suffix "po" in 1.3
xgettext-d $package $package. C |
Note: If the file is not ASC encoded, it must be indicated in the command above
--file-code= file Encoding
1.5 Edit the $PACKAGE.PO generated in 1.4, add the corresponding translation corresponding string
There are several languages in which separate edits are generated for several PO files
1.6 Calling the Linux system msgfmt to generate a binary file with the Po file suffix MO in 1.3 of 1.5
Msgfmt-o $package. Mo $package. po |
1.7 Establish the locale directory with the Bindtextdomain in 1.1 ($package, '/var/locale ');
In 1.1, for example, first in the/var/(existing) directory to establish the locale directory, the structure of the locale is
|--en_US | '--lc_messages | |--$package. Mo | |--ZH_CN | '--lc_messages | |--$package. Mo | '--ZH_TW '--lc_messages |--$package. Mo |
The first level of the directory is set according to the definition of $language_code in 1.1, it must be, otherwise cannot be found, the second level directory lc_messages is fixed, which contains 1.6 of the MO file generated
Second, because the website is smaty, we can extract the text from the template and put it in the language file.
Load by Smarty Config_load, if you put the language file in the directory $smarty->config_dir set
As long as the code contained in PHP, such as the following,
$smarty->config_load (' Chs.lang '); //$lang to pass Cookies or Session the page language value obtained Switch ($lang) { Case ' ZH-CN ': $smarty->config_load (' Chs.lang '); Break Case ' ZH-TW ': Header (' Cht.lang '); Break Default Header (' Cht.lang '); Break }
|
http://www.bkjia.com/PHPjc/446660.html www.bkjia.com true http://www.bkjia.com/PHPjc/446660.html techarticle first, the use of GetText, because Smarty have the corresponding GetText plug-ins, so directly with the plug-in the following steps: 1.1 in the public include the following code://$domain _i ...