In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What this article shares with you is a summary of how PHP Smarty strengthens its internationalization through gettext. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
First, adopt gettext, because Smarty has a plug-in corresponding to gettext, so use this plug-in directly
The steps are as follows:
1.1 add the following code to the public include file:
/ / $domain_info ['lang'] sets the value $language_code = $domain_info [' lang'] for the language passed in by cookie; / / the interface language is set to Chinese if ($language_code = = 'zh_CN') {/ / set the target language putenv ("LANG=$language_code"); setlocale (LC_ALL, $language_code); / / $package is the name of the mo file $package =' i18n accountabilization / path to bind the mo file bindtextdomain ($package,'/ var/locale') / / set the file name of the searched mo file textdomain ($package); / / specify the code bind_textdomain_codeset of the mo file to return to gettext ($package, 'UTF-8');} elseif ($language_code = =' BIG5') {/ / the interface language is set to traditional $language_code = 'zh_TW';putenv ("LANG=$language_code"); setlocale (LC_ALL, $language_code); $package =' i18n binary textdomain ($package,'/ var/locale'); textdomain ($package) Bind_textdomain_codeset ($package, 'UTF-8');} else {/ / the interface language is English / / set the target language putenv ("LANG=$language_code"); setlocale (LC_ALL, $language_code); / / $package is the name of the mo file $package =' i18n descriptor / path to bind the mo file bindtextdomain ($package,'/ var/locale'); / / set the file name textdomain ($package) of the searched mo file / / specify the encoding bind_textdomain_codeset of the mo file returned to gettext ($package, 'UTF-8');} / / * end of the process of adding an international language * /
1.2 add the t tag required by the smarty plug-in to the corresponding template
1.3 generate c files with the tools provided by the smarty plug-in
This c file extracts the tagged strings from all the templates.
Php-Q. / tsmarty2c.php * .html $package.c
Note: the name of the default c file is the same as that defined in 1.1
It should be noted that the open tag and close tag of the smarty defined in tsmarty2c.php must be consistent with the settings of the smarty configuration file
1.4 call the xgettext of the linux system to generate a file with the suffix po from the c file in 1.3.
Xgettext-d $package $package.c
Note: if the file is not Asc encoded, it must be specified in the above command.
-- file-code= file encoding
1.5 Edit the $package.po generated in 1.4 and add the corresponding translation string.
There are several languages, so edit and generate several po files separately.
1.6 call the msgfmt of the linux system to generate a binary file with the suffix mo from the po file in 1. 3
Msgfmt-o $package.mo $package.po
1.7 create the locale directory, which is the same as the bindtextdomain ($package,'/ var/locale'); in 1. 1
As an example, first set up the locale directory under the / var/ (existing) directory, and the structure of locale is
| |-- en_US | `--LC_MESSAGES | |-- $package.mo | |-- zh_CN |`-- LC_MESSAGES | |-- $package.mo | `--zh_ TW`-- LC_MESSAGES |-- $package.mo |
The * layer directory is set according to the definition of $language_code in 1.1. it must be like this, otherwise it cannot be found. The second layer directory LC_MESSAGES is fixed and contains the mo files generated in 1.6s.
Second, since the website uses Smaty, we can extract all the text from the template and concentrate it into the language file.
Load through smarty's config_load, on the premise that the language file is placed in the directory set by $smarty- > config_dir
As long as it is included in the php, the following code
$smarty- > config_load ('chs.lang'); / / $lang is the page language value switch ($lang) obtained through cookie or session {case' zh-cn': $smarty- > config_load ('chs.lang'); break; case' zh-tw': header ('cht.lang'); break; default:header (' cht.lang'); break } the above is a summary of how PHP Smarty strengthens its internationalization through gettext. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.