WordPress.org

Make WordPress Core

Ticket #4865: wp_counted_string.diff

File wp_counted_string.diff, 1.5 KB (added by darkdragon, 13 years ago)

Helper function for providing translatable plurals

  • formatting.php

     
    11<?php
     2/**
     3 * Functions used for formatting input and output
     4 *
     5 * @package WordPress
     6 */
    27
     8/**
     9 * wp_counted_string() - For formatting plurals in reference to translatable strings.
     10 *
     11 * If count is '0' then the $zero parameter string will be used. If count is '1' then
     12 * the $one parameter string will be used. If the count is more than '1' then the $more
     13 * parameter will be used.
     14 *
     15 * The $more string is expected to have '%' positioned where it is expected to appear in
     16 * relation to the string. The '%' will be replaced with the number.
     17 *
     18 * @since 2.4
     19 *
     20 * @param int $count The number to test against
     21 * @param string $zero The translatable string that would be used for zero amount
     22 * @param string $one The translatable string that would be used for one amount
     23 * @param string $more The translatable string that would be used for more than one amount
     24 * @return string The formatted translated string based off parameters.
     25 */
     26function wp_counted_string($count, $zero, $one, $more) {
     27        $posFormat = ( ('after' == $position) || (1 == $position) ) ? 1 : 0;
     28
     29        // Converted from comment-template.php lines 168 - 173
     30        $str = '';
     31        if( $count > 1 )
     32                return str_replace('%', $count, $more);
     33        else if ( $count == 0 )
     34                return $zero;
     35        else // Must be 1
     36                return $one;
     37}
     38
    339function wptexturize($text) {
    440        global $wp_cockneyreplace;
    541        $next = true;