Make WordPress Core

Changeset 13330


Ignore:
Timestamp:
02/23/2010 11:14:35 AM (15 years ago)
Author:
nacin
Message:

Introduce unload_textdomain() and add plugin_locale and theme_locale filters to load_*_textdomain() functions. Fixes #9686 props nbachiyski

File:
1 edited

Legend:

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

    r13304 r13330  
    316316
    317317/**
     318 * Unloads translations for a domain
     319 *
     320 * @since 3.0.0
     321 * @param string $domain Textdomain to be unloaded
     322 * @return bool Whether textdomain was unloaded
     323 */
     324function unload_textdomain( $domain ) {
     325    global $l10n;
     326
     327    $plugin_override = apply_filters( 'override_unload_textdomain', false, $domain );
     328
     329    if ( $plugin_override )
     330        return true;
     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 *
     
    345370 */
    346371function load_plugin_textdomain( $domain, $abs_rel_path = false, $plugin_rel_path = false ) {
    347     $locale = get_locale();
     372    $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
    348373
    349374    if ( false !== $plugin_rel_path ) {
     
    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';
    373 
    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     */
     394function load_muplugin_textdomain( $domain, $path = false ) {
     395    $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
    379396
    380397    $mofile = WPMU_PLUGIN_DIR . "/$domain-$locale.mo";
    381     load_textdomain($domain, $mofile);
     398    load_textdomain( $domain, $mofile );
    382399}
    383400
     
    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_filters( 'theme_locale', get_locale(), $domain );
    398415
    399416    $path = ( empty( $path ) ) ? get_template_directory() : $path;
     
    415432 * @param string $domain Unique identifier for retrieving translated strings
    416433 */
    417 function load_child_theme_textdomain($domain, $path = false) {
    418         $locale = get_locale();
    419 
    420         $path = ( empty( $path ) ) ? get_stylesheet_directory() : $path;
    421 
    422         $mofile = "$path/$locale.mo";
    423         return load_textdomain($domain, $mofile);
     434function load_child_theme_textdomain( $domain, $path = false ) {
     435    $locale = apply_filters( 'theme_locale', get_locale(), $domain );
     436
     437    $path = ( empty( $path ) ) ? get_stylesheet_directory() : $path;
     438
     439    $mofile = "$path/$locale.mo";
     440    return load_textdomain($domain, $mofile);
    424441}
    425442
Note: See TracChangeset for help on using the changeset viewer.