Make WordPress Core

Changeset 12251


Ignore:
Timestamp:
11/21/2009 09:28:32 AM (17 years ago)
Author:
westi
Message:

Allow plugins to override the behaviour of load_textdomain() in a variety of flexible ways. Fixes #11012 props johanee and nbachiyski.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/l10n.php

    r12231 r12251  
    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
    … …  
    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
    … …  
    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
    … …  
    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
    … …  
    240239 * @return string Either $single or $plural translated text
    241240 */
    242 function _n($single, $plural, $number, $domain = 'default') {
     241function _n( $single, $plural, $number, $domain = 'default' ) {
    243242        $translations = &get_translations_for_domain( $domain );
    244243        $translation = $translations->translate_plural( $single, $plural, $number );
    … …  
    321320 * @return bool true on success, false on failure
    322321 */
    323 function load_textdomain($domain, $mofile) {
     322function load_textdomain( $domain, $mofile ) {
    324323        global $l10n;
     324       
     325        $plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile );
     326       
     327        if ( true == $plugin_override ) {
     328                return true;
     329        }
     330       
     331        do_action( 'load_textdomain', $domain, $mofile );
     332               
     333        $mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );
    325334
    326335        if ( !is_readable( $mofile ) ) return false;
    … …  
    333342
    334343        $l10n[$domain] = &$mo;
     344       
    335345        return true;
    336346}
    … …  
    349359        $mofile = WP_LANG_DIR . "/$locale.mo";
    350360
    351         return load_textdomain('default', $mofile);
     361        return load_textdomain( 'default', $mofile );
    352362}
    353363
    … …  
    365375 * @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
    366376 */
    367 function load_plugin_textdomain($domain, $abs_rel_path = false, $plugin_rel_path = false) {
     377function load_plugin_textdomain( $domain, $abs_rel_path = false, $plugin_rel_path = false ) {
    368378        $locale = get_locale();
    369379
    370380        if ( false !== $plugin_rel_path )
    371                 $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/');
    372         else if ( false !== $abs_rel_path)
    373                 $path = ABSPATH . trim( $abs_rel_path, '/');
     381                $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
     382        else if ( false !== $abs_rel_path )
     383                $path = ABSPATH . trim( $abs_rel_path, '/' );
    374384        else
    375385                $path = WP_PLUGIN_DIR;
    376386
    377387        $mofile = $path . '/'. $domain . '-' . $locale . '.mo';
    378         return load_textdomain($domain, $mofile);
     388        return load_textdomain( $domain, $mofile );
    379389}
    380390
    … …  
    430440function &get_translations_for_domain( $domain ) {
    431441        global $l10n;
    432         if ( !isset($l10n[$domain]) ) {
     442        if ( !isset( $l10n[$domain] ) ) {
    433443                $l10n[$domain] = &new NOOP_Translations;
    434444        }
Note: See TracChangeset for help on using the changeset viewer.