From ddd44737149af98f363cd3969178b8dbc501c98c Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 30 Sep 2013 19:47:12 +0000 Subject: [PATCH] Send back core translation information to the API. Update wp_get_installed_translations() to work with core translations. see #18200. Built from https://develop.svn.wordpress.org/trunk@25652 git-svn-id: http://core.svn.wordpress.org/trunk@25569 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/l10n.php | 19 +++++++++++++------ wp-includes/update.php | 13 +++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 57e9a06b73..0687ca6b89 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -745,17 +745,22 @@ function get_available_languages( $dir = null ) { * * @since 3.7.0 * - * @param string $type What to search for. Accepts 'plugins', 'themes'. + * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'. * @return array Array of language data. */ function wp_get_installed_translations( $type ) { - if ( $type !== 'themes' && $type !== 'plugins' ) + if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' ) return array(); - if ( ! is_dir( WP_LANG_DIR ) || ! is_dir( WP_LANG_DIR . "/$type" ) ) + $dir = 'core' === $type ? '' : "/$type"; + + if ( ! is_dir( WP_LANG_DIR ) ) return array(); - $files = scandir( WP_LANG_DIR . "/$type" ); + if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) + return array(); + + $files = scandir( WP_LANG_DIR . $dir ); if ( ! $files ) return array(); @@ -766,11 +771,13 @@ function wp_get_installed_translations( $type ) { continue; if ( substr( $file, -3 ) !== '.po' ) continue; - if ( ! preg_match( '/(.*)-([A-Za-z_]{2,6}).po/', $file, $match ) ) + if ( ! preg_match( '/(?:(.+)-)?([A-Za-z_]{2,6}).po/', $file, $match ) ) continue; list( , $textdomain, $language ) = $match; - $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "/$type/$file" ); + if ( '' === $textdomain ) + $textdomain = 'default'; + $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" ); } return $language_data; } diff --git a/wp-includes/update.php b/wp-includes/update.php index 1d2e1cba17..79903f5a03 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -28,6 +28,8 @@ function wp_version_check() { $php_version = phpversion(); $current = get_site_transient( 'update_core' ); + $translations = wp_get_installed_translations( 'core' ); + if ( ! is_object($current) ) { $current = new stdClass; $current->updates = array(); @@ -85,10 +87,13 @@ function wp_version_check() { 'headers' => array( 'wp_install' => $wp_install, 'wp_blog' => home_url( '/' ) - ) + ), + 'body' => array( + 'translations' => json_encode( $translations ), + ), ); - $response = wp_remote_get($url, $options); + $response = wp_remote_post( $url, $options ); if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) return false; @@ -119,6 +124,10 @@ function wp_version_check() { $updates->updates = $offers; $updates->last_checked = time(); $updates->version_checked = $wp_version; + + if ( isset( $body['translations'] ) ) + $updates->translations = $body['translations']; + set_site_transient( 'update_core', $updates); }