X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/5aa86a9053fb0fa15846bb60aac2fb8fdfff524a..6c8f14c09105d0afa4c1574215c59b5021040e76:/wp-includes/l10n.php diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 733f3a44..750e08de 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -65,7 +65,7 @@ function get_locale() { * @return string Translated text */ function translate( $text, $domain = 'default' ) { - $translations = &get_translations_for_domain( $domain ); + $translations = get_translations_for_domain( $domain ); return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain ); } @@ -78,7 +78,7 @@ function before_last_bar( $string ) { } function translate_with_gettext_context( $text, $context, $domain = 'default' ) { - $translations = &get_translations_for_domain( $domain ); + $translations = get_translations_for_domain( $domain ); return apply_filters( 'gettext_with_context', $translations->translate( $text, $context ), $text, $context, $domain ); } @@ -236,7 +236,7 @@ function esc_html_x( $single, $context, $domain = 'default' ) { * @return string Either $single or $plural translated text */ function _n( $single, $plural, $number, $domain = 'default' ) { - $translations = &get_translations_for_domain( $domain ); + $translations = get_translations_for_domain( $domain ); $translation = $translations->translate_plural( $single, $plural, $number ); return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain ); } @@ -249,7 +249,7 @@ function _n( $single, $plural, $number, $domain = 'default' ) { * */ function _nx($single, $plural, $number, $context, $domain = 'default') { - $translations = &get_translations_for_domain( $domain ); + $translations = get_translations_for_domain( $domain ); $translation = $translations->translate_plural( $single, $plural, $number, $context ); return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain ); } @@ -272,10 +272,11 @@ function _nx($single, $plural, $number, $context, $domain = 'default') { * @since 2.5 * @param string $singular Single form to be i18ned * @param string $plural Plural form to be i18ned + * @param string $domain Optional. The domain identifier the text will be retrieved in * @return array array($singular, $plural) */ -function _n_noop( $singular, $plural ) { - return array( 0 => $singular, 1 => $plural, 'singular' => $singular, 'plural' => $plural, 'context' => null ); +function _n_noop( $singular, $plural, $domain = null ) { + return array( 0 => $singular, 1 => $plural, 'singular' => $singular, 'plural' => $plural, 'context' => null, 'domain' => $domain ); } /** @@ -283,8 +284,8 @@ function _n_noop( $singular, $plural ) { * * @see _n_noop() */ -function _nx_noop( $singular, $plural, $context ) { - return array( 0 => $singular, 1 => $plural, 2 => $context, 'singular' => $singular, 'plural' => $plural, 'context' => $context ); +function _nx_noop( $singular, $plural, $context, $domain = null ) { + return array( 0 => $singular, 1 => $plural, 2 => $context, 'singular' => $singular, 'plural' => $plural, 'context' => $context, 'domain' => $domain ); } /** @@ -293,9 +294,13 @@ function _nx_noop( $singular, $plural, $context ) { * @since 3.1 * @param array $nooped_plural Array with singular, plural and context keys, usually the result of _n_noop() or _nx_noop() * @param int $count Number of objects - * @param string $domain Optional. The domain identifier the text should be retrieved in + * @param string $domain Optional. The domain identifier the text should be retrieved in. If $nooped_plural contains + * a domain passed to _n_noop() or _nx_noop(), it will override this value. */ function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) { + if ( $nooped_plural['domain'] ) + $domain = $nooped_plural['domain']; + if ( $nooped_plural['context'] ) return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain ); else @@ -382,9 +387,17 @@ function load_default_textdomain() { load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" ); - if ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) { + if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) { load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" ); + return; } + + if ( is_admin() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) + load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" ); + + if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) + load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" ); + } /** @@ -446,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); } @@ -465,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 ); } /** @@ -480,7 +497,7 @@ function load_child_theme_textdomain( $domain, $path = false ) { * @param string $domain * @return object A Translation instance */ -function &get_translations_for_domain( $domain ) { +function get_translations_for_domain( $domain ) { global $l10n; if ( !isset( $l10n[$domain] ) ) { $l10n[$domain] = new NOOP_Translations; @@ -527,7 +544,8 @@ function get_available_languages( $dir = null ) { foreach( (array)glob( ( is_null( $dir) ? WP_LANG_DIR : $dir ) . '/*.mo' ) as $lang_file ) { $lang_file = basename($lang_file, '.mo'); - if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) ) + if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) && + 0 !== strpos( $lang_file, 'admin-' )) $languages[] = $lang_file; }