WordPress.org

Make WordPress Core

Ticket #9686: hooks-and-unload_textdomain.2.diff

File hooks-and-unload_textdomain.2.diff, 3.0 KB (added by nbachiyski, 8 years ago)
  • wp-includes/l10n.php

     
    6969        return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain );
    7070}
    7171
    72 function before_last_bar( $string ) {
     72function before_last_bar( $string ) {   
    7373        $last_bar = strrpos( $string, '|' );
    7474        if ( false == $last_bar )
    7575                return $string;
     
    310310                $mo->merge_with( $l10n[$domain] );
    311311
    312312        $l10n[$domain] = &$mo;
    313 
     313               
    314314        return true;
    315315}
    316316
    317317/**
     318 * Unloads translations for a domain
     319 *
     320 * @since 3.0
     321 * @param string $domain Textdomain to be unloaded
     322 */
     323function unload_textdomain( $domain ) {
     324        global $l10n;
     325
     326        $plugin_override = apply_filters( 'override_unload_textdomain', false, $domain );
     327
     328        if ( true == $plugin_override ) {
     329                return true;
     330        }
     331
     332        do_action( 'unload_textdomain', $domain );
     333       
     334        if ( isset( $l10n[$domain] ) ) {
     335                unset( $l10n[$domain] );
     336                return true;
     337        }
     338       
     339        return false;
     340}
     341
     342/**
    318343 * Loads default translated strings based on locale.
    319344 *
    320345 * Loads the .mo file in WP_LANG_DIR constant path from WordPress root. The
     
    344369 * @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
    345370 */
    346371function load_plugin_textdomain( $domain, $abs_rel_path = false, $plugin_rel_path = false ) {
    347         $locale = get_locale();
     372        $locale = apply_filter( 'plugin_locale', get_locale(), $domain );
    348373
    349374        if ( false !== $plugin_rel_path ) {
    350375                $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
     
    366391 *
    367392 * @param string $domain Unique identifier for retrieving translated strings
    368393 */
    369 function load_muplugin_textdomain($domain, $path = false) {
    370         $locale = get_locale();
    371         if ( empty($locale) )
    372                 $locale = 'en_US';
     394function load_muplugin_textdomain( $domain ) {
     395        $locale = apply_filter( 'plugin_locale', get_locale(), $domain );
    373396
    374         /* @todo $path is not used.  Was it ever used and was it expected to be an arbitrary absolute dir?
    375          * Ideally, it should be relative to WPMU_PLUGIN_DUR.
    376         if ( false === $path )
    377                 $path = WPMU_PLUGIN_DIR;
    378         */
    379 
    380397        $mofile = WPMU_PLUGIN_DIR . "/$domain-$locale.mo";
    381         load_textdomain($domain, $mofile);
     398        load_textdomain( $domain, $mofile );
    382399}
    383400
    384401/**
     
    393410 *
    394411 * @param string $domain Unique identifier for retrieving translated strings
    395412 */
    396 function load_theme_textdomain($domain, $path = false) {
    397         $locale = get_locale();
     413function load_theme_textdomain( $domain, $path = false ) {
     414        $locale = apply_filter( 'theme_locale', get_locale(), $domain );
    398415
    399416        $path = ( empty( $path ) ) ? get_template_directory() : $path;
    400417
     
    414431 *
    415432 * @param string $domain Unique identifier for retrieving translated strings
    416433 */
    417 function load_child_theme_textdomain($domain, $path = false) {
     434function load_child_theme_textdomain( $domain, $path = false ) {
    418435        $locale = get_locale();
    419436
    420437        $path = ( empty( $path ) ) ? get_stylesheet_directory() : $path;