本文整理汇总了PHP中I18n::getText方法的典型用法代码示例。如果您正苦于以下问题:PHP I18n::getText方法的具体用法?PHP I18n::getText怎么用?PHP I18n::getText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类I18n
的用法示例。
在下文中一共展示了I18n::getText方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __
/**
* This function is as flexible as possible, you can choose your own pattern for variables in
* the string.
*
* Examples of variables are: ':var_name', '#var_name', '{varname}',
* '%varname', '%varname%', 'VARNAME', etc...
*
* <code>
* return = array('hello world!' => 'bonjour le monde!',
* 'user ":user" is logged in' => 'l\'utilisateur ":user" est connecté',
* 'Posted by %user% on %month% %day% %year% at %time%' => 'Publié par %user% le %day% %month% %year% à %time%'
* );
*
* __('hello world!'); // bonjour le monde!
* __('user ":user" is logged in', array(':user' => $user)); // l'utilisateur "demo" est connecté
* __('Posted by %user% on %month% %day% %year% at %time%', array(
* '%user%' => $user,
* '%month%' => __($month),
* '%day%' => $day,
* '%year%' => $year,
* '%time%' => $time)); // Publié par demo le 3 janvier 2006 à 19:30
* </code>
*/
function __($string, $args = null)
{
$string = I18n::getText($string);
if ($args === null) {
return $string;
}
return strtr($string, $args);
}
示例2: __
/**
* This function is as flexible as possible, you can choose your own pattern for variables in
* the string.
*
* Examples of variables are: ':var_name', '#var_name', '{varname}',
* '%varname', '%varname%', 'VARNAME', etc...
*
* <code>
* return = array('hello world!' => 'bonjour le monde!',
* 'user ":user" is logged in' => 'l\'utilisateur ":user" est connecté',
* 'Posted by %user% on %month% %day% %year% at %time%' => 'Publié par %user% le %day% %month% %year% à %time%'
* );
*
* __('hello world!'); // bonjour le monde!
* __('user ":user" is logged in', array(':user' => $user)); // l'utilisateur "demo" est connecté
* __('Posted by %user% on %month% %day% %year% at %time%', array(
* '%user%' => $user,
* '%month%' => __($month),
* '%day%' => $day,
* '%year%' => $year,
* '%time%' => $time)); // Publié par demo le 3 janvier 2006 à 19:30
* </code>
*/
function __($string, $args = null)
{
if (I18n::getLocale() != DEFAULT_LOCALE) {
$string = I18n::getText($string);
}
if ($args === null) {
return $string;
}
return strtr($string, $args);
}