本文整理汇总了PHP中PO::translate方法的典型用法代码示例。如果您正苦于以下问题:PHP PO::translate方法的具体用法?PHP PO::translate怎么用?PHP PO::translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PO
的用法示例。
在下文中一共展示了PO::translate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _t
//.........这里部分代码省略.........
*
* Having passed strings through t() in a dummy function, it is then
* okay to pass variables through t().
*
* Correct (if a dummy file was used):
* @code
* $time = new Time();
* $output .= t($time->today);
* @endcode
*
* However tempting it is, custom data from user input or other non-code
* sources should not be passed through t(). Doing so leads to the following
* problems and errors:
* - The t() system doesn't support updates to existing strings. When user
* data is updated, the next time it's passed through t() a new record is
* created instead of an update. The database bloats over time and any
* existing translations are orphaned with each update.
* - The t() system assumes any data it receives is in English. User data may
* be in another language, producing translation errors.
* - The "Built-in interface" text group in the locale system is used to
* produce translations for storage in .po files. When non-code strings are
* passed through t(), they are added to this text group, which is rendered
* inaccurate since it is a mix of actual interface strings and various user
* input strings of uncertain origin.
*
* Incorrect:
* @code
* $item = item_load();
* $output .= check_plain(t($item['title']));
* @endcode
*
* Instead, translation of these data can be done through the locale system,
* either directly or through helper functions provided by contributed
* modules.
* @see hook_locale()
*
* During installation, st() is used in place of t(). Code that may be called
* during installation or during normal operation should use the get_t()
* helper function.
* @see st()
* @see get_t()
*
* @param $string
* A string containing the English string to translate.
* @param $args
* An associative array of replacements to make after translation. Incidences
* of any key in this array are replaced with the corresponding value. Based
* on the first character of the key, the value is escaped and/or themed:
* - !variable: inserted as is
* - @variable: escape plain text to HTML (check_plain)
* - %variable: escape text and theme as a placeholder for user-submitted
* content (check_plain + theme_placeholder)
* @param $langcode
* Optional language code to translate to a language other than what is used
* to display the page.
* @return
* The translated string.
*/
function _t($string, $args = array(), $langcode = NULL, $reset = FALSE)
{
global $language, $cfg;
static $locale_t = NULL;
//@TODO se quiser fazer texto custom
if ($reset) {
// Reset in-memory cache.
$locale_t = NULL;
}
if (!isset($string)) {
// Return all cached strings if no string was specified
return $locale_t;
}
$langcode = isset($langcode) ? $langcode : $language['language']->language;
//@TODO verificr se esta consumindo muita memoria qualquer coisa cachear
if (isset($language['translate'])) {
$po = new PO();
$po->merge_with($language['translate']);
$string = $po->translate($string);
}
if (empty($args)) {
return $string;
} else {
// Transform arguments before inserting them.
foreach ($args as $key => $value) {
switch ($key[0]) {
case '@':
// Escaped only.
$args[$key] = check_plain($value);
break;
case '%':
default:
//@todo Escaped and placeholder.
//$args[$key] = theme('placeholder', $value);
break;
case '!':
// Pass-through.
}
}
return strtr($string, $args);
}
}