Make WordPress Core

Ticket #11012: load_textdomain-hook.2.diff

File load_textdomain-hook.2.diff, 4.7 KB (added by nbachiyski, 15 years ago)
  • wp-includes/l10n.php

     
    2828function get_locale() {
    2929        global $locale;
    3030
    31         if (isset($locale))
     31        if ( isset( $locale ) )
    3232                return apply_filters( 'locale', $locale );
    3333
    3434        // WPLANG is defined in wp-config.
    35         if (defined('WPLANG'))
     35        if ( defined( 'WPLANG' ) )
    3636                $locale = WPLANG;
    3737
    38         if (empty($locale))
     38        if ( empty( $locale ) )
    3939                $locale = 'en_US';
    4040
    41         return apply_filters('locale', $locale);
     41        return apply_filters( 'locale', $locale );
    4242}
    4343
    4444/**
     
    5656 */
    5757function translate( $text, $domain = 'default' ) {
    5858        $translations = &get_translations_for_domain( $domain );
    59         return apply_filters('gettext', $translations->translate($text), $text, $domain);
     59        return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain );
    6060}
    6161
    6262function before_last_bar( $string ) {
     
    8080 */
    8181function translate_with_context( $text, $domain = 'default' ) {
    8282        return before_last_bar( translate( $text, $domain ) );
    83 
    8483}
    8584
    8685function translate_with_gettext_context( $text, $context, $domain = 'default' ) {
    8786        $translations = &get_translations_for_domain( $domain );
    88         return apply_filters( 'gettext_with_context', $translations->translate( $text, $context ), $text, $context, $domain);
     87        return apply_filters( 'gettext_with_context', $translations->translate( $text, $context ), $text, $context, $domain );
    8988}
    9089
    9190/**
     
    195194 * @param string $domain Optional. Domain to retrieve the translated text
    196195 * @return string Translated context string without pipe
    197196 */
    198 function _c($text, $domain = 'default') {
    199         return translate_with_context($text, $domain);
     197function _c( $text, $domain = 'default' ) {
     198        return translate_with_context( $text, $domain );
    200199}
    201200
    202201function _x( $single, $context, $domain = 'default' ) {
     
    235234 * @param string $domain Optional. The domain identifier the text should be retrieved in
    236235 * @return string Either $single or $plural translated text
    237236 */
    238 function _n($single, $plural, $number, $domain = 'default') {
     237function _n( $single, $plural, $number, $domain = 'default' ) {
    239238        $translations = &get_translations_for_domain( $domain );
    240239        $translation = $translations->translate_plural( $single, $plural, $number );
    241240        return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain );
     
    316315 * @param string $mofile Path to the .mo file
    317316 * @return bool true on success, false on failure
    318317 */
    319 function load_textdomain($domain, $mofile) {
     318function load_textdomain( $domain, $mofile ) {
    320319        global $l10n;
     320       
     321        $plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile );
     322       
     323        if ( true == $plugin_override ) {
     324                return true;
     325        }
     326       
     327        do_action( 'load_textdomain', $domain, $mofile );
     328               
     329        $mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );
    321330
    322331        if ( !is_readable( $mofile ) ) return false;
    323332
     
    328337                $mo->merge_with( $l10n[$domain] );
    329338
    330339        $l10n[$domain] = &$mo;
     340       
    331341        return true;
    332342}
    333343
     
    344354
    345355        $mofile = WP_LANG_DIR . "/$locale.mo";
    346356
    347         return load_textdomain('default', $mofile);
     357        return load_textdomain( 'default', $mofile );
    348358}
    349359
    350360/**
     
    360370 *      where the .mo file resides. Deprecated, but still functional until 2.7
    361371 * @param string $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR. This is the preferred argument to use. It takes precendence over $abs_rel_path
    362372 */
    363 function load_plugin_textdomain($domain, $abs_rel_path = false, $plugin_rel_path = false) {
     373function load_plugin_textdomain( $domain, $abs_rel_path = false, $plugin_rel_path = false ) {
    364374        $locale = get_locale();
    365375
    366376        if ( false !== $plugin_rel_path )
    367                 $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/');
    368         else if ( false !== $abs_rel_path)
    369                 $path = ABSPATH . trim( $abs_rel_path, '/');
     377                $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
     378        else if ( false !== $abs_rel_path )
     379                $path = ABSPATH . trim( $abs_rel_path, '/' );
    370380        else
    371381                $path = WP_PLUGIN_DIR;
    372382
    373383        $mofile = $path . '/'. $domain . '-' . $locale . '.mo';
    374         return load_textdomain($domain, $mofile);
     384        return load_textdomain( $domain, $mofile );
    375385}
    376386
    377387/**
     
    404414 */
    405415function &get_translations_for_domain( $domain ) {
    406416        global $l10n;
    407         if ( !isset($l10n[$domain]) ) {
     417        if ( !isset( $l10n[$domain] ) ) {
    408418                $l10n[$domain] = &new NOOP_Translations;
    409419        }
    410420        return $l10n[$domain];
     
    421431 * won't suffer from that problem.
    422432 */
    423433function translate_user_role( $name ) {
    424         return translate_with_gettext_context( before_last_bar($name), 'User role' );
    425 }
    426 ?>
     434        return translate_with_gettext_context( before_last_bar( $name ), 'User role' );
     435}
     436 No newline at end of file