Ticket #8128: contextual-ngettext.diff
File contextual-ngettext.diff, 1.9 KB (added by , 15 years ago) |
---|
-
wp-includes/l10n.php
70 70 return apply_filters('gettext', $text, $text, $domain); 71 71 } 72 72 73 function before_last_bar( $string ) { 74 $last_bar = strrpos( $string, '|' ); 75 if ( false == $last_bar ) 76 return $string; 77 else 78 return substr( $string, 0, $last_bar ); 79 } 80 73 81 /** 74 82 * Retrieve the translated text and strip context. 75 83 * … … 86 94 * @param string $domain Domain to retrieve the translated text 87 95 * @return string Translated text 88 96 */ 89 function translate_with_context($text, $domain = 'default') { 90 $whole = translate($text, $domain); 91 $last_bar = strrpos($whole, '|'); 92 if ( false == $last_bar ) { 93 return $whole; 94 } else { 95 return substr($whole, 0, $last_bar); 96 } 97 function translate_with_context( $text, $domain = 'default' ) { 98 return before_last_bar( translate( $text, $domain ) ); 99 97 100 } 98 101 99 102 /** … … 182 185 } 183 186 184 187 /** 188 * @see __ngettext() An alias of __ngettext 189 * 190 */ 191 function _n() { 192 $args = func_get_args(); 193 return call_user_func_array('__ngettext', $args); 194 } 195 196 /** 197 * @see _n() A version of _n(), which supports contexts -- 198 * strips everything from the translation after the last bar 199 * 200 */ 201 function _nc( $single, $plural, $number, $domain = 'default' ) { 202 return before_last_bar( __ngettext( $single, $plural, $number, $domain ) ); 203 } 204 205 /** 185 206 * Register plural strings in POT file, but don't translate them. 186 207 * 187 208 * Used when you want do keep structures with translatable plural strings and … … 208 229 } 209 230 210 231 /** 232 * @see __ngettext_noop() An alias of __ngettext_noop() 233 * 234 */ 235 function _n_noop() { 236 $args = func_get_args(); 237 return call_user_func_array('__ngettext_noop', $args); 238 } 239 240 /** 211 241 * Loads MO file into the list of domains. 212 242 * 213 243 * If the domain already exists, the inclusion will fail. If the MO file is not