From 8984b71035dca342b59878797f9f4a847c47a9ac Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Tue, 20 Aug 2013 12:33:07 +0000 Subject: [PATCH] Allow for plugin translations to be loaded from WP_LANG_DIR/plugins/$domain-$locale.mo. props dimadin. see #18200. git-svn-id: https://develop.svn.wordpress.org/trunk@25059 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/l10n.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php index 4df86ba60a..0f2e9f383b 100644 --- a/src/wp-includes/l10n.php +++ b/src/wp-includes/l10n.php @@ -447,7 +447,13 @@ function load_plugin_textdomain( $domain, $abs_rel_path = false, $plugin_rel_pat $path = WP_PLUGIN_DIR; } - $mofile = $path . '/'. $domain . '-' . $locale . '.mo'; + // Load the textdomain according to the plugin first + $mofile = $domain . '-' . $locale . '.mo'; + if ( $loaded = load_textdomain( $domain, $path . '/'. $mofile ) ) + return $loaded; + + // Otherwise, load from the languages directory + $mofile = WP_LANG_DIR . '/plugins/' . $mofile; return load_textdomain( $domain, $mofile ); } @@ -462,8 +468,16 @@ function load_plugin_textdomain( $domain, $abs_rel_path = false, $plugin_rel_pat */ function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); - $path = WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ); - load_textdomain( $domain, trailingslashit( $path ) . "$domain-$locale.mo" ); + $path = trailingslashit( WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ) ); + + // Load the textdomain according to the plugin first + $mofile = $domain . '-' . $locale . '.mo'; + if ( $loaded = load_textdomain( $domain, $path . $mofile ) ) + return $loaded; + + // Otherwise, load from the languages directory + $mofile = WP_LANG_DIR . '/plugins/' . $mofile; + return load_textdomain( $domain, $mofile ); } /** @@ -484,14 +498,14 @@ function load_theme_textdomain( $domain, $path = false ) { if ( ! $path ) $path = get_template_directory(); - // Load the textdomain from the Theme provided location, or theme directory first + // Load the textdomain according to the theme $mofile = "{$path}/{$locale}.mo"; - if ( $loaded = load_textdomain($domain, $mofile) ) + if ( $loaded = load_textdomain( $domain, $mofile ) ) return $loaded; - // Else, load textdomain from the Language directory + // Otherwise, load from the languages directory $mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo"; - return load_textdomain($domain, $mofile); + return load_textdomain( $domain, $mofile ); } /**