gettext
(PHP 4, PHP 5, PHP 7)
gettext - 在当前域中查找消息
描述
string gettext ( string $message )
在当前域中查找消息。
参数
message
正在翻译的消息。
返回值
如果在翻译表中找到翻译的字符串,则返回翻译的字符串;如果找不到,则返回提交的消息。
示例
Example #1 gettext()-check
<?php
//?Set?language?to?German
putenv('LC_ALL=de_DE');
setlocale(LC_ALL,?'de_DE');
//?Specify?location?of?translation?tables
bindtextdomain("myPHPApp",?"./locale");
//?Choose?domain
textdomain("myPHPApp");
//?Translation?is?looking?for?in?./locale/de_DE/LC_MESSAGES/myPHPApp.mo?now
//?Print?a?test?message
echo?gettext("Welcome?to?My?PHP?Application");
//?Or?use?the?alias?_()?for?gettext()
echo?_("Have?a?nice?day");
?>
注意
注意:您可以使用下划线字符'_'作为此函数的别名。
注意:为某些系统设置语言是不够的,应使用putenv()来定义当前语言环境。
另请参阅
- setlocale() - 设置区域设置信息
← dngettext
ngettext →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com