本文整理汇总了PHP中i18n::lookup方法的典型用法代码示例。如果您正苦于以下问题:PHP i18n::lookup方法的具体用法?PHP i18n::lookup怎么用?PHP i18n::lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类i18n
的用法示例。
在下文中一共展示了i18n::lookup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mktime
/**
* Format a date
*
* Accept either a time stamp, or a formatted string as input parameter:
* - YYYY-MM-DD HH:MM:SS
* - YYMMDD HH:MM:SS GMT
*
* The variant is processed as follows:
* - 'day' - only day, month and year --no time information
* - 'with_hour' - adapts to time scale, and mention hours for today and yesterday
* - 'no_hour' - adapts to time scale, but don't mention hours
* - 'full' - display the full date
* - 'month' - only month and year
* - 'publishing' - allows for smart skinning
* - 'standalone' - like full, but without the 'on ' prefix
* - 'iso8601' - special format
* - 'plain' - example 'Feb 26 2010 22:30:31 GMT'
* - 'yyyy-mm-dd' - only day, month and year --no time information
*
* The date provided is considered to be GMT-based.
* It is adjusted to the time zone of the surfer, if applicable.
* This adjustment does not apply to following variants:
* - 'day'
* - 'iso8601'
* - 'standalone'
*
*
* @link http://www.w3.org/TR/NOTE-datetime the w3c profile of ISO 8601
* @link http://www.cs.tut.fi/~jkorpela/iso8601.html short description of ISO 8601
* @link http://fr2.php.net/date Code for ISO 8601 formatting
*
* @param int or string the date to be displayed
* @param string the variant
* @param string the language to express this stamp
* @param int offset to GMT of the provided date, if any
* @return the HTML to be used
*/
public static function &build_date($stamp, $variant = 'with_hour', $language = NULL, $gmt_offset = 0)
{
global $context, $local;
// return by reference
$output = '';
// sanity check
if (!isset($stamp) || !$stamp) {
return $output;
}
// surfer offset, except on 'day' and 'iso8601'
if ($variant == 'day' || $variant == 'iso8601' || $variant == 'standalone' || $variant == 'local') {
$surfer_offset = 0;
} else {
$surfer_offset = Surfer::get_gmt_offset();
}
// YYMMDD-HH:MM:SS GMT -- this one is natively GMT
if (preg_match('/GMT$/', $stamp) && strlen($stamp) == 19) {
// YYMMDD-HH:MM:SS GMT -> HH, MM, SS, MM, DD, YY
$actual_stamp = mktime(substr($stamp, 7, 2), substr($stamp, 10, 2), substr($stamp, 13, 2), substr($stamp, 2, 2), substr($stamp, 4, 2), substr($stamp, 0, 2));
// adjust to surfer time zone
$actual_stamp += $surfer_offset * 3600;
// time()-like stamp
} elseif (intval($stamp) > 10000000) {
// adjust to surfer time zone
$actual_stamp = intval($stamp) + ($surfer_offset - $gmt_offset) * 3600;
// YYYY-MM-DD HH:MM:SS, or a string that can be readed
} elseif (($actual_stamp = strtotime($stamp)) != -1) {
// adjust to surfer time zone
$actual_stamp += ($surfer_offset - $gmt_offset) * 3600;
} else {
$output = '*' . $stamp . '*';
return $output;
}
if (!($items = @getdate($actual_stamp))) {
$output = '*' . $stamp . '*';
return $output;
}
// if undefined language, use preferred language for absolute formats
if ($language) {
} elseif ($variant == 'full' || $variant == 'iso8601' || $variant == 'local') {
$language = $context['preferred_language'];
} else {
$language = $context['language'];
}
// in French '1' -> '1er'
if ($language == 'fr' && $items['mday'] == 1) {
$items['mday'] = '1er';
}
// allow for months localization through i18n
$months = array('*', i18n::s('Jan.'), i18n::s('Feb.'), i18n::s('Mar.'), i18n::s('Apr.'), i18n::s('May'), i18n::s('June'), i18n::s('Jul.'), i18n::s('Aug.'), i18n::s('Sep.'), i18n::s('Oct.'), i18n::s('Nov.'), i18n::s('Dec.'));
// load month labels adapted to required language
$months = array('*', i18n::lookup($context['l10n'][$language], 'Jan.'), i18n::lookup($context['l10n'][$language], 'Feb.'), i18n::lookup($context['l10n'][$language], 'Mar.'), i18n::lookup($context['l10n'][$language], 'Apr.'), i18n::lookup($context['l10n'][$language], 'May'), i18n::lookup($context['l10n'][$language], 'June'), i18n::lookup($context['l10n'][$language], 'Jul.'), i18n::lookup($context['l10n'][$language], 'Aug.'), i18n::lookup($context['l10n'][$language], 'Sep.'), i18n::lookup($context['l10n'][$language], 'Oct.'), i18n::lookup($context['l10n'][$language], 'Nov.'), i18n::lookup($context['l10n'][$language], 'Dec.'));
// now
$now = time();
// server actual offset -- provided as a parameter
// $gmt_offset = intval((strtotime(date('M d Y H:i:s')) - strtotime(gmdate('M d Y H:i:s'))) / 3600);
// server stamp, as seen by surfer
$today = getdate($now + ($surfer_offset - $gmt_offset) * 3600);
// time stamp only
if (preg_match('/00:00/', date('H:i', $actual_stamp))) {
$time = '';
} else {
$trailer = '';
//.........这里部分代码省略.........
示例2:
/**
* get a localized string for a surfer
*
* This function is an equivalent to gettext(), except it deals with surfer localization.
*
* @param string the template string to be translated
* @return string the localized string, if any
*/
public static function &s($text)
{
global $context;
// sanity check
if (!$text) {
return $text;
}
// select language used by surfer
if (isset($context['language'])) {
$locale = $context['language'];
} else {
$locale = 'en';
}
// cache is empty
if (!isset($context['l10n']) || !isset($context['l10n'][$locale]) || !is_array($context['l10n'][$locale])) {
return $text;
}
// provide the localized string
$text =& i18n::lookup($context['l10n'][$locale], $text);
return $text;
}