| | 878 | function 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 | |