本文整理汇总了PHP中Locale::ngettext方法的典型用法代码示例。如果您正苦于以下问题:PHP Locale::ngettext方法的具体用法?PHP Locale::ngettext怎么用?PHP Locale::ngettext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locale
的用法示例。
在下文中一共展示了Locale::ngettext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: relative_time
/**
* Make a timestamp into a relative string
*
* @todo Tidy up and move out of this file.
* Based on Garrett Murray's code from http://graveyard.maniacalrage.net/etc/relative/
*/
function relative_time($posted_date)
{
$in_seconds = $posted_date;
$diff = time() - $in_seconds;
$months = floor($diff / 2592000);
$diff -= $months * 2419200;
$weeks = floor($diff / 604800);
$diff -= $weeks * 604800;
$days = floor($diff / 86400);
$diff -= $days * 86400;
$hours = floor($diff / 3600);
$diff -= $hours * 3600;
$minutes = floor($diff / 60);
$diff -= $minutes * 60;
$seconds = $diff;
if ($months > 0) {
return sprintf(_c('on %s', 'on <date>'), date('N, jS \\o\\f F, Y'));
}
switch (true) {
case $weeks > 0:
// weeks and days
$week = sprintf(Locale::ngettext('%d week', '%d weeks', $weeks), $weeks);
if ($days > 0) {
$day = sprintf(Locale::ngettext('%d day', '%d days', $days), $days);
$relative_date = sprintf(_c('%s, %s ago', 'relative time, "x weeks, x days ago"'), $week, $day);
} else {
$relative_date = sprintf(_c('%s ago', 'relative time, "x weeks ago"'), $week);
}
break;
case $days > 0:
// days and hours
$day = sprintf(Locale::ngettext('%d day', '%d days', $days), $days);
if ($hours > 0) {
$hour = sprintf(Locale::ngettext('%d hour', '%d hours', $hours), $hours);
$relative_date = sprintf(_c('%s, %s ago', 'relative time, "x days, x hours ago"'), $day, $hour);
} else {
$relative_date = sprintf(_c('%s ago', 'relative time, "x days ago"'), $day);
}
break;
case $hours > 0:
// hours and minutes
$hour = sprintf(Locale::ngettext('%d hour', '%d hours', $hours), $hours);
if ($minutes > 0) {
$minute = sprintf(Locale::ngettext('%d minute', '%d minutes', $minutes), $minutes);
$relative_date = sprintf(_c('%s, %s ago', 'relative time, "x hours, x minutes ago"'), $hour, $minute);
} else {
$relative_date = sprintf(_c('%s ago', 'relative time, "x hours ago"'), $hour);
}
break;
case $minutes > 0:
// minutes only
return sprintf(Locale::ngettext('%d minute ago', '%d minutes ago', $minutes), $minutes);
break;
case $seconds > 0:
// seconds only
return sprintf(Locale::ngettext('%d second ago', '%d seconds ago', $seconds), $seconds);
break;
}
return $relative_date;
}
示例2: import_opml
/**
* Parse feeds into an array, ready to pass to the Javascript importer
*
* @param string $opml OPML standard file.
* @return array Associative array containing feed URL, title and category (if applicable)
*/
protected function import_opml($opml)
{
if (empty($opml)) {
throw new Exception(_r('No OPML specified'));
return false;
}
$opml = new OPMLParser($opml);
if (!empty($opml->error) || empty($opml->data)) {
throw new Exception(sprintf(_r('The OPML file could not be read. The parser said: %s'), $opml->error));
return false;
}
$feeds_num = 0;
foreach ($opml->data as $cat => $feed) {
if (!isset($feed['xmlurl']) && isset($feed[0]['xmlurl'])) {
foreach ($feed as $subfeed) {
$feeds[] = array('url' => $subfeed['xmlurl'], 'title' => $subfeed['title'], 'cat' => $cat);
++$feeds_num;
}
continue;
}
$feeds[] = array('url' => $feed['xmlurl'], 'title' => $feed['title'], 'cat' => '');
++$feeds_num;
}
MessageHandler::add(sprintf(Locale::ngettext('Adding %d feed', 'Adding %d feeds', $feeds_num), $feeds_num));
return $feeds;
}
示例3: import_opml
/**
* Parse feeds into an array, ready to pass to the Javascript importer
*
* @param string $opml OPML standard file.
* @return array Associative array containing feed URL, title and category (if applicable)
*/
protected function import_opml($opml)
{
if (empty($opml)) {
throw new Exception(_r('No OPML specified'));
return false;
}
$opml = new OPMLParser($opml);
if (!empty($opml->error) || empty($opml->data)) {
throw new Exception(sprintf(_r('The OPML file could not be read. The parser said: %s'), $opml->error));
return false;
}
$feeds_num = 0;
$feeds = $this->parse($opml->data);
MessageHandler::add(sprintf(Locale::ngettext('Adding %d feed', 'Adding %d feeds', $feeds_num), $feeds_num));
return $feeds;
}
示例4: __ngettext
/**
* Display a translated string
*
* __ngettext() is a convenience function which displays the returned
* translated text from Locale::ngettext().
*
* @see Locale::ngettext() Echos returned Locale::ngettext() string
* @since 1.0
*
* @param string $single The text that will be used if $number is 1
* @param string $plural The text that will be used if $number is not 1
* @param int $number The number to compare against to use either $single or $plural
* @param string $domain Optional. The domain identifier the text should be retrieved in
* @return string Either $single or $plural translated text
*/
function __ngettext($single, $plural, $number, $domain = 'default')
{
echo Locale::ngettext($single, $plural, $number, $domain);
}
示例5: cron
protected function cron()
{
set_time_limit(0);
ItemUpdater::set_feeds(Feeds::get_instance()->getAll());
ItemUpdater::$fatal = false;
foreach (ItemUpdater::process() as $feed => $updated) {
$name = Feeds::get_instance()->get($feed);
$name = $name['name'];
if ($updated < 0) {
$text = 'An error occurred while updating feed "%1$s".';
} else {
$text = Locale::ngettext('Updated feed "%1$s". Added %2$d item.', 'Updated feed "%1$s". Added %2$d items.', $updated);
}
$messages[] = array('msg' => sprintf($text, $name, $updated), 'updated' => $updated);
}
if (isset($_GET['output'])) {
return array('success' => 1, 'msgs' => $messages);
} else {
die;
}
}