I18N: Add changes missed in [37415].

See #34114.
Built from https://develop.svn.wordpress.org/trunk@37416


git-svn-id: http://core.svn.wordpress.org/trunk@37382 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2016-05-10 20:31:27 +00:00
parent 751234a580
commit 64fb1a9e90
2 changed files with 54 additions and 2 deletions

View File

@ -782,6 +782,58 @@ function load_child_theme_textdomain( $domain, $path = false ) {
return load_theme_textdomain( $domain, $path );
}
/**
* Just in time loading of plugin and theme textdomains.
*
* When a textdomain is encountered for the first time, we try to load the translation file
* from wp-content/languages, removing the need to call `load_plugin_texdomain()` or
* `load_theme_texdomain()`. Holds a cached list of available .mo files to improve performance.
*
* @since 4.6.0
* @access private
*
* @see get_translations_for_domain()
*
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return bool True when the textdomain is successfully loaded, false otherwise.
*/
function _load_textdomain_just_in_time( $domain ) {
static $cached_mofiles = null;
// Short-circuit if domain is 'default' which is reserved for core.
if ( 'default' === $domain ) {
return false;
}
if ( null === $cached_mofiles ) {
$cached_mofiles = array();
$locations = array(
WP_LANG_DIR . '/plugins',
WP_LANG_DIR . '/themes',
);
foreach ( $locations as $location ) {
foreach ( get_available_languages( $location ) as $file ) {
$cached_mofiles[] = "{$location}/{$file}.mo";
}
}
}
$locale = get_locale();
$mofile = "{$domain}-{$locale}.mo";
if ( in_array( WP_LANG_DIR . '/plugins/' . $mofile, $cached_mofiles ) ) {
return load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile );
}
if ( in_array( WP_LANG_DIR . '/themes/' . $mofile, $cached_mofiles ) ) {
return load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile );
}
return false;
}
/**
* Return the Translations instance for a text domain.
*
@ -796,7 +848,7 @@ function load_child_theme_textdomain( $domain, $path = false ) {
*/
function get_translations_for_domain( $domain ) {
global $l10n;
if ( isset( $l10n[ $domain ] ) ) {
if ( isset( $l10n[ $domain ] ) || _load_textdomain_just_in_time( $domain ) ) {
return $l10n[ $domain ];
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.6-alpha-37415';
$wp_version = '4.6-alpha-37416';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.