Make WordPress Core

Ticket #22229: 22229.diff

File 22229.diff, 2.0 KB (added by nacin, 12 years ago)
  • wp-includes/script-loader.php

     
    6363
    6464        $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), false, 1 );
    6565        did_action( 'init' ) && $scripts->localize( 'common', 'commonL10n', array(
    66                 'warnDelete' => __("You are about to permanently delete the selected items.\n  'Cancel' to stop, 'OK' to delete.")
     66                'warnDelete' => __("You are about to permanently delete the selected items.\n  'Cancel' to stop, 'OK' to delete."),
     67                'l10n_print_after' => wp_js_i18n_plural( 'commonL10n.testPlural', _n_noop( 'Singular', '%d Plural' ) )
    6768        ) );
    6869
    6970        $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 );
     
    874875        }
    875876}
    876877
     878function wp_js_i18n_plural( $variable, $n_noop ) {
     879        if ( ! did_action( 'init' ) )
     880                return;
     881
     882        $domain = $n_noop['domain'] ? $n_noop['domain'] : 'default';
     883        $mo = get_translations_for_domain( $domain );
     884
     885        $entry = new Translation_Entry( array( 'singular' => $n_noop['singular'], 'plural' => $n_noop['plural'], 'context' => $n_noop['context'] ) );
     886        if ( $translated = $mo->translate_entry( $entry ) ) {
     887                $translations = $translated->translations;
     888                list( $nplurals, $expression ) = $mo->nplurals_and_expression_from_header( $mo->get_header( 'Plural-Forms' ) );
     889        } else {
     890                $translations = array( $n_noop['singular'], $n_noop['plural'] );
     891                $nplurals = 2;
     892                $expression = 'n != 1';
     893        }
     894        $nplurals--;
     895
     896        return "$variable = function(n) {\n\tvar i = ($expression),\n\t\tt = " . json_encode( (object) $translations )
     897                . ",\n\tstring;\n\tif (typeof i === 'boolean') i = i ? 1 : 0;\n\tstring = i > $nplurals ? t[$nplurals] : t[i];"
     898                . "\n\treturn string.replace(/%(s|d)/, n);}";
     899}
     900
    877901add_action( 'wp_default_scripts', 'wp_default_scripts' );
    878902add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
    879903add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );