WordPress.org

Make WordPress Core

Changeset 25520


Ignore:
Timestamp:
09/20/2013 07:12:45 PM (8 years ago)
Author:
nacin
Message:

Send installed language data to the plugin and theme update-check endpoints.

Introduces wp_get_installed_language_data() and wp_get_pomo_file_data().

see #18200.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r25493 r25520  
    626626    return $languages;
    627627}
     628
     629/**
     630 * Get installed language data.
     631 *
     632 * Looks in the wp-content/languages directory for translations of
     633 * plugins or themes.
     634 *
     635 * @since 3.7.0
     636 *
     637 * @param string $type What to search for. Accepts 'plugins', 'themes'.
     638 * @return array Array of language data.
     639 */
     640function wp_get_installed_language_data( $type ) {
     641    if ( $type !== 'themes' && $type !== 'plugins' )
     642        return array();
     643
     644    if ( ! is_dir( WP_LANG_DIR ) || ! is_dir( WP_LANG_DIR . "/$type" ) )
     645        return array();
     646
     647    $files = scandir( WP_LANG_DIR . "/$type" );
     648    if ( ! $files )
     649        return array();
     650
     651    $language_data = array();
     652
     653    foreach ( $files as $file ) {
     654        if ( '.' === $file[0] || is_dir( $file ) )
     655            continue;
     656        if ( substr( $file, -3 ) !== '.po' )
     657            continue;
     658        if ( ! preg_match( '/(.*)-([A-Za-z_]{2,6}).po/', $file, $match ) )
     659            continue;
     660
     661        list( , $textdomain, $language ) = $match;
     662        $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "/$type/$file" );
     663    }
     664    return $language_data;
     665}
     666
     667/**
     668 * Extract headers from a PO file.
     669 *
     670 * @since 3.7.0
     671 *
     672 * @param string $po_file Path to PO file.
     673 * @return array PO file headers.
     674 */
     675function wp_get_pomo_file_data( $po_file ) {
     676    $headers = get_file_data( $po_file, array(
     677        'POT-Creation-Date'  => '"POT-Creation-Date',
     678        'PO-Revision-Date'   => '"PO-Revision-Date',
     679        'Project-Id-Version' => '"Project-Id-Version',
     680        'X-Generator'        => '"X-Generator',
     681    ) );
     682    foreach ( $headers as &$header ) {
     683        // Remove possible contextual '\n' and closing double quote.
     684        $header = preg_replace( '~(\\\n)?"$~', '', $header );
     685    }
     686    return $headers;
     687}
  • trunk/src/wp-includes/update.php

    r25514 r25520  
    147147
    148148    $plugins = get_plugins();
     149    $languages = wp_get_installed_language_data( 'plugins' );
     150
    149151    $active  = get_option( 'active_plugins', array() );
    150152    $current = get_site_transient( 'update_plugins' );
     
    201203    $options = array(
    202204        'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
    203         'body' => array( 'plugins' => json_encode( $to_send ) ),
     205        'body' => array( 'plugins' => json_encode( $to_send ), 'languages' => json_encode( $languages ) ),
    204206        'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
    205207    );
     
    244246
    245247    $installed_themes = wp_get_themes();
     248    $languages = wp_get_installed_language_data( 'themes' );
     249
    246250    $last_update = get_site_transient( 'update_themes' );
    247251    if ( ! is_object($last_update) )
     
    311315    $options = array(
    312316        'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
    313         'body'          => array( 'themes' => json_encode( $request ) ),
     317        'body'          => array( 'themes' => json_encode( $request ), 'languages' => json_encode( $languages ) ),
    314318        'user-agent'    => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
    315319    );
Note: See TracChangeset for help on using the changeset viewer.