I18N: Reverse the order of loading plugin and theme translations.
`load_theme_textdomain()`, `load_plugin_textdomain()` and `load_muplugin_textdomain()` now try to load the .mo file from the `wp-content/languages` directory first. After the introduction of language packs, translation files are more likely to be located there. Props swissspidy, sebastian.pisula. Fixes #34213. Built from https://develop.svn.wordpress.org/trunk@37414 git-svn-id: http://core.svn.wordpress.org/trunk@37380 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1564bd2c1f
commit
3f6966907b
|
@ -655,6 +655,7 @@ function load_default_textdomain( $locale = null ) {
|
||||||
* The .mo file should be named based on the text domain with a dash, and then the locale exactly.
|
* The .mo file should be named based on the text domain with a dash, and then the locale exactly.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
* @since 4.6.0 The function now tries to load the .mo file from the languages directory first.
|
||||||
*
|
*
|
||||||
* @param string $domain Unique identifier for retrieving translated strings
|
* @param string $domain Unique identifier for retrieving translated strings
|
||||||
* @param string $deprecated Use the $plugin_rel_path parameter instead.
|
* @param string $deprecated Use the $plugin_rel_path parameter instead.
|
||||||
|
@ -663,7 +664,6 @@ function load_default_textdomain( $locale = null ) {
|
||||||
* @return bool True when textdomain is successfully loaded, false otherwise.
|
* @return bool True when textdomain is successfully loaded, false otherwise.
|
||||||
*/
|
*/
|
||||||
function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
|
function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
|
||||||
$locale = get_locale();
|
|
||||||
/**
|
/**
|
||||||
* Filter a plugin's locale.
|
* Filter a plugin's locale.
|
||||||
*
|
*
|
||||||
|
@ -672,7 +672,14 @@ function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path
|
||||||
* @param string $locale The plugin's current locale.
|
* @param string $locale The plugin's current locale.
|
||||||
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
||||||
*/
|
*/
|
||||||
$locale = apply_filters( 'plugin_locale', $locale, $domain );
|
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
|
||||||
|
|
||||||
|
$mofile = $domain . '-' . $locale . '.mo';
|
||||||
|
|
||||||
|
// Try to load from the languages directory first.
|
||||||
|
if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ( false !== $plugin_rel_path ) {
|
if ( false !== $plugin_rel_path ) {
|
||||||
$path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
|
$path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
|
||||||
|
@ -683,20 +690,14 @@ function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path
|
||||||
$path = WP_PLUGIN_DIR;
|
$path = WP_PLUGIN_DIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the textdomain according to the plugin first
|
return load_textdomain( $domain, $path . '/' . $mofile );
|
||||||
$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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the translated strings for a plugin residing in the mu-plugins directory.
|
* Load the translated strings for a plugin residing in the mu-plugins directory.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
|
* @since 4.6.0 The function now tries to load the .mo file from the languages directory first.
|
||||||
*
|
*
|
||||||
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
||||||
* @param string $mu_plugin_rel_path Relative to WPMU_PLUGIN_DIR directory in which the .mo file resides.
|
* @param string $mu_plugin_rel_path Relative to WPMU_PLUGIN_DIR directory in which the .mo file resides.
|
||||||
|
@ -706,16 +707,17 @@ function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path
|
||||||
function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
|
function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
|
||||||
/** This filter is documented in wp-includes/l10n.php */
|
/** This filter is documented in wp-includes/l10n.php */
|
||||||
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
|
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
|
||||||
|
|
||||||
|
$mofile = $domain . '-' . $locale . '.mo';
|
||||||
|
|
||||||
|
// Try to load from the languages directory first.
|
||||||
|
if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$path = trailingslashit( WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ) );
|
$path = trailingslashit( WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ) );
|
||||||
|
|
||||||
// Load the textdomain according to the plugin first
|
return load_textdomain( $domain, $path . '/' . $mofile );
|
||||||
$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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -727,6 +729,7 @@ function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
|
||||||
* The .mo files must be named based on the locale exactly.
|
* The .mo files must be named based on the locale exactly.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
* @since 4.6.0 The function now tries to load the .mo file from the languages directory first.
|
||||||
*
|
*
|
||||||
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
||||||
* @param string $path Optional. Path to the directory containing the .mo file.
|
* @param string $path Optional. Path to the directory containing the .mo file.
|
||||||
|
@ -734,7 +737,6 @@ function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
|
||||||
* @return bool True when textdomain is successfully loaded, false otherwise.
|
* @return bool True when textdomain is successfully loaded, false otherwise.
|
||||||
*/
|
*/
|
||||||
function load_theme_textdomain( $domain, $path = false ) {
|
function load_theme_textdomain( $domain, $path = false ) {
|
||||||
$locale = get_locale();
|
|
||||||
/**
|
/**
|
||||||
* Filter a theme's locale.
|
* Filter a theme's locale.
|
||||||
*
|
*
|
||||||
|
@ -743,19 +745,20 @@ function load_theme_textdomain( $domain, $path = false ) {
|
||||||
* @param string $locale The theme's current locale.
|
* @param string $locale The theme's current locale.
|
||||||
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
||||||
*/
|
*/
|
||||||
$locale = apply_filters( 'theme_locale', $locale, $domain );
|
$locale = apply_filters( 'theme_locale', get_locale(), $domain );
|
||||||
|
|
||||||
if ( ! $path )
|
$mofile = $domain . '-' . $locale . '.mo';
|
||||||
|
|
||||||
|
// Try to load from the languages directory first.
|
||||||
|
if ( load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $path ) {
|
||||||
$path = get_template_directory();
|
$path = get_template_directory();
|
||||||
|
}
|
||||||
|
|
||||||
// Load the textdomain according to the theme
|
return load_textdomain( $domain, $path . '/' . $locale . '.mo' );
|
||||||
$mofile = untrailingslashit( $path ) . "/{$locale}.mo";
|
|
||||||
if ( $loaded = load_textdomain( $domain, $mofile ) )
|
|
||||||
return $loaded;
|
|
||||||
|
|
||||||
// Otherwise, load from the languages directory
|
|
||||||
$mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo";
|
|
||||||
return load_textdomain( $domain, $mofile );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.6-alpha-37413';
|
$wp_version = '4.6-alpha-37414';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue