本文整理汇总了PHP中pluralize函数的典型用法代码示例。如果您正苦于以下问题:PHP pluralize函数的具体用法?PHP pluralize怎么用?PHP pluralize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pluralize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_taxonomy
public function add_taxonomy($name, $args = array(), $labels = array())
{
if (!empty($name)) {
// We need to know the post type name, so the new taxonomy can be attached to it.
$post_type_name = $this->post_type_name;
// Taxonomy properties
$taxonomy_name = uglify($name);
$taxonomy_labels = $labels;
$taxonomy_args = $args;
if (!taxonomy_exists($taxonomy_name)) {
//Capitilize the words and make it plural
$name = beautify($name);
$plural = pluralize($name);
// Default labels, overwrite them with the given labels.
$labels = array_merge(array('name' => _x($plural, 'taxonomy general name', $this->post_domain), 'singular_name' => _x($name, 'taxonomy singular name', $this->post_domain), 'search_items' => __('Search ' . $plural, $this->post_domain), 'all_items' => __('All ' . $plural, $this->post_domain), 'parent_item' => __('Parent ' . $name, $this->post_domain), 'parent_item_colon' => __('Parent ' . $name . ':', $this->post_domain), 'edit_item' => __('Edit ' . $name, $this->post_domain), 'update_item' => __('Update ' . $name, $this->post_domain), 'add_new_item' => __('Add New ' . $name, $this->post_domain), 'new_item_name' => __('New ' . $name . ' Name', $this->post_domain), 'menu_name' => __($name, $this->post_domain)), $taxonomy_labels);
// Default arguments, overwitten with the given arguments
$args = array_merge(array('label' => $plural, 'labels' => $labels, 'public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, '_builtin' => false), $taxonomy_args);
// Add the taxonomy to the post type
add_action('init', function () use($taxonomy_name, $post_type_name, $args) {
register_taxonomy($taxonomy_name, $post_type_name, $args);
});
} else {
add_action('init', function () use($taxonomy_name, $post_type_name) {
register_taxonomy_for_object_type($taxonomy_name, $post_type_name);
});
}
}
}
示例2: get_posted_records
function get_posted_records()
{
$record_set = $this->controller->params['ActiveRecord'];
if (!$record_set) {
return;
}
foreach ($record_set as $class_name => $object_set) {
foreach ($object_set as $id => $updated_fields) {
if (preg_match('/new-.*/', $id)) {
$obj = new $class_name();
$action = 'new';
} else {
$obj = new $class_name($id);
$action = 'updated';
}
$obj->mergeData($updated_fields);
$posted_record_collection = $action . '_' . snake_case(pluralize($class_name));
if (!isset($this->controller->{$posted_record_collection})) {
$this->controller->{$posted_record_collection} = array();
}
$this->controller->posted_records[$class_name][$action][] = $obj;
$this->controller->{$posted_record_collection}[] = $obj;
}
}
}
示例3: route_makeRequest
public function route_makeRequest()
{
$type = pluralize(strip_tags($_GET['type']));
set_time_limit(0);
$fp = fopen("../{$type}/latest.zip", 'w+');
$url = str_replace(" ", "%20", strip_tags($_GET['url']));
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
# write curl response to file
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$zip = new ZipArchive();
if ($zip->open("../{$type}/latest.zip") == true) {
mkdir("../{$type}/latest", 0777);
$zip->extractTo("../{$type}/latest");
$zip->close();
$handle = opendir("../{$type}/latest");
if ($handle) {
while (($file = readdir($handle)) !== false) {
if (is_dir("../{$type}/latest/{$file}")) {
if ($file != '.' and $file != '..') {
rename("../{$type}/latest/{$file}", "../{$type}/{$file}");
}
}
}
}
$this->rrmdir("../{$type}/latest");
unlink("../{$type}/latest.zip");
$this->rrmdir("../{$type}/__MACOSX");
}
Flash::notice(__("Extension downloaded successfully.", "extension_manager"), "/admin/?action=extend_manager");
}
示例4: test_irregular
public function test_irregular()
{
foreach (require __DIR__ . '/cases/fr/irregular.php' as $singular => $plural) {
$this->assertEquals($singular, singularize($plural, 'fr'));
$this->assertEquals($plural, pluralize($singular, 'fr'));
}
}
示例5: testPluralizeObject
public function testPluralizeObject()
{
// arrange
// act
$result = pluralize((object) ['Felix', 'Tom'], 'cat');
// assert
$this->assertEquals('2 cats', $result);
}
示例6: new_taxonomy
/**
* Create a new taxonomy.
*
* @param string $name
* The name of the taxonomy.
* @param $post_types
* @param boolean $hierarchical (optional)
*
* @ingroup helperfunc
*/
function new_taxonomy($name, $post_types, $hierarchical = true)
{
if (!is_array($name)) {
$name = array("singular" => $name, "plural" => pluralize($name));
}
$uc_plural = ucwords(preg_replace("/_/", " ", $name["plural"]));
$uc_singular = ucwords(preg_replace("/_/", " ", $name["singular"]));
$labels = array("name" => $uc_singular, "singular_name" => $uc_singular, "search_items" => sprintf(__("Search %s", "we"), $uc_plural), "all_items" => sprintf(__("All %s", "we"), $uc_plural), "parent_item" => sprintf(__("Parent %s", "we"), $uc_singular), "parent_item_colon" => sprintf(__("Parent %s:", "we"), $uc_singular), "edit_item" => sprintf(__("Edit %s", "we"), $uc_singular), "update_item" => sprintf(__("Update %s", "we"), $uc_singular), "add_new_item" => sprintf(__("Add new %s", "we"), $uc_singular), "new_item_name" => sprintf(__("New %n Name", "we"), $uc_singular), "menu_name" => $uc_plural);
register_taxonomy($name["singular"], $post_types, array('hierarchical' => $hierarchical, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => $name["plural"])));
}
示例7: validates_confirmation_of
function validates_confirmation_of($model, $field, $options = array())
{
$params = array_merge($_GET, $_POST);
$model_name = strtolower(get_class($model));
if (isset($params[$model_name][$field])) {
if ($params[$model_name]["confirm_{$field}"] != $model->fields[$field]) {
add_error_message_to($model, $field, !$options['custom_message'] ? pluralize(humanize($field)) . " do not match." : $options['custom_message']);
}
unset($model->fields["confirm_{$field}"]);
}
}
示例8: jal_time_since
function jal_time_since($original)
{
if (!isset($_SESSION['Year'])) {
$_SESSION['Year'] = __('year', wordspew);
$_SESSION['years'] = __('years', wordspew);
$_SESSION['Month'] = __('month', wordspew);
$_SESSION['months'] = __('months', wordspew);
$_SESSION['Week'] = __('week', wordspew);
$_SESSION['weeks'] = __('weeks', wordspew);
$_SESSION['Day'] = __('day', wordspew);
$_SESSION['days'] = __('days', wordspew);
$_SESSION['Hour'] = __('hour', wordspew);
$_SESSION['hours'] = __('hours', wordspew);
$_SESSION['Minute'] = __('minute', wordspew);
$_SESSION['minutes'] = __('minutes', wordspew);
}
// array of time period chunks
$chunks = array(array(60 * 60 * 24 * 365, $_SESSION['Year'], $_SESSION['years']), array(60 * 60 * 24 * 30, $_SESSION['Month'], $_SESSION['months']), array(60 * 60 * 24 * 7, $_SESSION['Week'], $_SESSION['weeks']), array(60 * 60 * 24, $_SESSION['Day'], $_SESSION['days']), array(60 * 60, $_SESSION['Hour'], $_SESSION['hours']), array(60, $_SESSION['Minute'], $_SESSION['minutes']));
$original = $original - 10;
// Shaves a second, eliminates a bug where $time and $original match.
$today = time();
/* Current unix time */
$since = $today - $original;
// $j saves performing the count function each time around the loop
for ($i = 0, $j = count($chunks); $i < $j; $i++) {
$seconds = $chunks[$i][0];
$name = $chunks[$i][1];
$name_s = $chunks[$i][2];
// finding the biggest chunk (if the chunk fits, break)
if (($count = floor($since / $seconds)) != 0) {
break;
}
}
$print = $count . " " . pluralize($count, $name, $name_s);
if ($i + 1 < $j) {
// now getting the second item
$seconds2 = $chunks[$i + 1][0];
$name2 = $chunks[$i + 1][1];
$name2_s = $chunks[$i + 1][2];
// add second item if it's greater than 0
if (($count2 = floor(($since - $seconds * $count) / $seconds2)) != 0) {
$print .= ", " . $count2 . " " . pluralize($count2, $name2, $name2_s);
}
}
return $print;
}
示例9: deliver
function deliver($view, $data)
{
$headers = array();
$headers[] = "From: {$this->from}";
if (isset($this->reply_to)) {
$headers[] = "Return-Path: {$this->reply_to}";
}
$class_name = strtolower(pluralize(str_replace('Mailer', '', get_class($this))));
// Load HTML View
if (!isset($this->html) && file_exists(APPLICATION_ROOT . "/app/views/{$class_name}/{$view}.php")) {
ob_start();
require APPLICATION_ROOT . "/app/views/{$class_name}/{$view}.php";
$this->html = ob_get_contents();
ob_end_clean();
}
// Load Text View
if (!isset($this->text) && file_exists(APPLICATION_ROOT . "/app/views/{$class_name}/{$view}_text.php")) {
ob_start();
require APPLICATION_ROOT . "/app/views/{$class_name}/{$view}_text.php";
$this->text = ob_get_contents();
ob_end_clean();
}
$mime_boundary = '=' . md5(time());
// Headers
$headers[] = "From: {$this->from}";
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-Type: multipart/alternative; boundary=\"{$mime_boundary}\"";
// Mashed Body
$body .= "--{$mime_boundary}\n";
$body .= "Content-Type: text/plain; charset=iso-8859-1\n";
$body .= "Content-Transfer-Encoding: 8bit\n\n";
$body .= "{$this->text}\n\n";
$body .= "--{$mime_boundary}\n";
$body .= "Content-Type: text/html; charset=iso-8859-1\n";
$body .= "Content-Transfer-Encoding: quoted-printable\n\n";
$body .= "{$this->html}\n\n";
$body .= "--{$mime_boundary}--\n\n";
foreach ($this->recipients as $recipient) {
mail($recipient, $this->subject, $body, join($headers, "\n"));
}
}
示例10: calculateDiff
function calculateDiff($dayDelta, $minuteDelta)
{
if ($dayDelta != 'null' && $dayDelta != '0') {
if ($dayDelta < 0) {
$diff = "-" . pluralize(abs(intval($dayDelta)) . " day");
} else {
if ($dayDelta > 0) {
$diff = "+" . pluralize(intval($dayDelta) . " day");
}
}
} else {
$diff = "";
}
if ($minuteDelta != 'null' && $minuteDelta != '0') {
if ($minuteDelta < 0) {
$diff .= "-" . pluralize(abs(intval($minuteDelta)) . " minute");
} else {
$diff .= "+" . pluralize(intval($minuteDelta) . " minute");
}
}
return $diff;
}
示例11: age
/**
* Returns the age of a date/time.
*
* Usage example:
* {$order.date_created|age} # 27 minutes ago
*/
function age($params, $delay = 0)
{
$date = is_array($params) && $params['of'] ? $params['of'] : $params;
// Make sure we have a timestamp.
$time = is_numeric($date) ? (int) $date : strtotime($date);
$seconds_elapsed = time() - $time - $delay;
// Seconds.
if ($seconds_elapsed < 60) {
return 'just now';
} else {
if ($seconds_elapsed >= 60 && $seconds_elapsed < 3600) {
$age = floor($seconds_elapsed / 60) . ' ' . pluralize(array('word' => 'minute', 'if_many' => floor($seconds_elapsed / 60)));
} else {
if ($seconds_elapsed >= 3600 && $seconds_elapsed < 86400) {
$age = floor($seconds_elapsed / 3600) . ' ' . pluralize(array('word' => 'hour', 'if_many' => floor($seconds_elapsed / 3600)));
} else {
if ($seconds_elapsed >= 86400 && $seconds_elapsed < 604800) {
$age = floor($seconds_elapsed / 86400) . ' ' . pluralize(array('word' => 'day', 'if_many' => floor($seconds_elapsed / 86400)));
} else {
if ($seconds_elapsed >= 604800 && $seconds_elapsed < 2626560) {
$age = floor($seconds_elapsed / 604800) . ' ' . pluralize(array('word' => 'week', 'if_many' => floor($seconds_elapsed / 604800)));
} else {
if ($seconds_elapsed >= 2626560 && $seconds_elapsed < 31536000) {
$age = floor($seconds_elapsed / 2626560) . ' ' . pluralize(array('word' => 'month', 'if_many' => floor($seconds_elapsed / 2626560)));
} else {
if ($seconds_elapsed >= 31536000) {
$age = floor($seconds_elapsed / 31536000) . ' ' . pluralize(array('word' => 'year', 'if_many' => floor($seconds_elapsed / 31536000)));
}
}
}
}
}
}
}
return "{$age} ago";
}
示例12: filterText
<?php
if (!isset($this->twitchObj->data['memberCard']['memberID'])) {
exit;
}
$twitchObj = $this->twitchObj;
?>
<div class='twitchCardContainer'>
<div class='twitchPreview'>
<?php
if ($twitchObj->data['memberCard']['online']) {
echo "\n\t\t\t\t<div class='twitchLiveIcon'></div>\n\t\t\t\t<div class='twitchGameOverlay'><img src='" . $twitchObj->getGameImageURL($twitchObj->data['memberCard']['game']) . "' onmouseover=\"showToolTip('" . filterText($twitchObj->data['memberCard']['game']) . "')\" onmouseout=\"hideToolTip()\"></div>\n\t\t\t\t<div class='twitchViewers'>" . number_format($twitchObj->data['memberCard']['viewers']) . " " . pluralize("viewer", $twitchObj->data['memberCard']['viewers']) . "</div>\n\t\t\t\t<a href='" . MAIN_ROOT . "plugins/twitch/?user=" . $twitchObj->data['memberCard']['memberInfo']['username'] . "'><img src='" . $twitchObj->data['memberCard']['rawData']['stream']['preview']['medium'] . "'></a>\n\t\t\t";
} else {
echo "<a href='" . MAIN_ROOT . "plugins/twitch/?user=" . $twitchObj->data['memberCard']['memberInfo']['username'] . "'><img src='" . MAIN_ROOT . "plugins/twitch/images/offlinepreview.png'></a>";
}
?>
</div>
<div class='twitchChannelDescription ellipsis' title='<?php
echo filterText($twitchObj->data['memberCard']['streamTitle']);
?>
'><?php
echo $twitchObj->data['memberCard']['streamTitle'];
?>
</div>
<div class='twitchChannelDescription'><?php
echo $twitchObj->data['memberCard']['memberLink'];
?>
streaming as <a href='http://twitch.tv/<?php
示例13: pluralize
function pluralize($what)
{
if ($what == "this") {
return "these";
} else {
if ($what == "has") {
return "have";
} else {
if ($what == "is") {
return "are";
} else {
if (str_ends_with($what, ")") && preg_match('/\\A(.*?)(\\s*\\([^)]*\\))\\z/', $what, $m)) {
return pluralize($m[1]) . $m[2];
} else {
if (preg_match('/\\A.*?(?:s|sh|ch|[bcdfgjklmnpqrstvxz][oy])\\z/', $what)) {
if (substr($what, -1) == "y") {
return substr($what, 0, -1) . "ies";
} else {
return $what . "es";
}
} else {
return $what . "s";
}
}
}
}
}
}
示例14: table
protected static function table()
{
return pluralize(dash(get_called_class()));
}
示例15: disable
/**
* Function: disable
* Disables a module or feather.
*/
public function disable()
{
$config = Config::current();
$visitor = Visitor::current();
$type = isset($_GET['module']) ? "module" : "feather";
if (!$visitor->group->can("toggle_extensions")) {
if ($type == "module") {
show_403(__("Access Denied"), __("You do not have sufficient privileges to enable/disable modules."));
} else {
show_403(__("Access Denied"), __("You do not have sufficient privileges to enable/disable feathers."));
}
}
if ($type == "module" and !module_enabled($_GET[$type])) {
Flash::warning(__("Module already disabled."), "/admin/?action=modules");
}
if ($type == "feather" and !feather_enabled($_GET[$type])) {
Flash::warning(__("Feather already disabled."), "/admin/?action=feathers");
}
$enabled_array = $type == "module" ? "enabled_modules" : "enabled_feathers";
$folder = $type == "module" ? MODULES_DIR : FEATHERS_DIR;
$class_name = camelize($_GET[$type]);
if (method_exists($class_name, "__uninstall")) {
call_user_func(array($class_name, "__uninstall"), false);
}
$config->set($type == "module" ? "enabled_modules" : "enabled_feathers", array_diff($config->{$enabled_array}, array($_GET[$type])));
$info = YAML::load($folder . "/" . $_GET[$type] . "/info.yaml");
if ($type == "module") {
Flash::notice(_f("“%s” module disabled.", array($info["name"])), "/admin/?action=" . pluralize($type));
} elseif ($type == "feather") {
Flash::notice(_f("“%s” feather disabled.", array($info["name"])), "/admin/?action=" . pluralize($type));
}
}