From 57785c7feadca2e7f98b45842e879242aae9f2f2 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 31 Oct 2012 21:30:33 +0000 Subject: [PATCH] Theme Translations: Allow for theme pomo files to be loaded from WP_LANG_DIR/themes/{$domain}-{$locale}.(p|m)o. This directory format is what we have chosen for Language Packs (See #18200), but which is currently delayed. By making this change, we can ship localised theme files within core for bundled themes, and avoid the issues associated with Theme Updates overwriting/removing the language files. Fixes #18960 git-svn-id: http://core.svn.wordpress.org/trunk@22346 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/l10n.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 4062339acd..750e08dec4 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -459,9 +459,16 @@ function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { function load_theme_textdomain( $domain, $path = false ) { $locale = apply_filters( 'theme_locale', get_locale(), $domain ); - $path = ( empty( $path ) ) ? get_template_directory() : $path; + if ( ! $path ) + $path = get_template_directory(); - $mofile = "$path/$locale.mo"; + // Load the textdomain from the Theme provided location, or theme directory first + $mofile = "{$path}/{$locale}.mo"; + if ( $loaded = load_textdomain($domain, $mofile) ) + return $loaded; + + // Else, load textdomain from the Language directory + $mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo"; return load_textdomain($domain, $mofile); } @@ -478,12 +485,9 @@ function load_theme_textdomain( $domain, $path = false ) { * @param string $domain Unique identifier for retrieving translated strings */ function load_child_theme_textdomain( $domain, $path = false ) { - $locale = apply_filters( 'theme_locale', get_locale(), $domain ); - - $path = ( empty( $path ) ) ? get_stylesheet_directory() : $path; - - $mofile = "$path/$locale.mo"; - return load_textdomain($domain, $mofile); + if ( ! $path ) + $path = get_stylesheet_directory(); + return load_theme_textdomain( $domain, $path ); } /**