Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/22/2013 11:24:01 PM (13 years ago)
Author:
djpaul
Message:

Introduces automatic download of BuddyPress translations from translate.wordpress.org. Fixes #4857

BuddyPress now uses cron to periodically check if the version of the current locale's translation on translate.wordpress.org is more recent than the installed version.
If an update is available, the "Updates" badge's count in the WordPress admin menu is incremented, and a new button on the Updates screen allows a site admin to update the translation to that latest version.
This improves user experience for everyone who wants to use BuddyPress in their native language.

Thanks to markoheijnen for help making changes to GlotPress to enable this functionality.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-functions.php

    r7093 r7097  
    12681268 */
    12691269function bp_core_load_buddypress_textdomain() {
    1270         $locale        = apply_filters( 'buddypress_locale', get_locale() );
    1271         $mofile        = sprintf( 'buddypress-%s.mo', $locale );
    1272         $mofile_global = WP_LANG_DIR . '/' . $mofile;
    1273         $mofile_local  = BP_PLUGIN_DIR . 'bp-languages/' . $mofile;
    1274 
    1275         if ( file_exists( $mofile_global ) )
    1276                 return load_textdomain( 'buddypress', $mofile_global );
    1277         elseif ( file_exists( $mofile_local ) )
    1278                 return load_textdomain( 'buddypress', $mofile_local );
    1279         else
    1280                 return false;
    1281 }
    1282 add_action ( 'bp_core_loaded', 'bp_core_load_buddypress_textdomain' );
     1270        $locale      = apply_filters( 'buddypress_locale', get_locale() );
     1271        $mofile      = sprintf( 'buddypress-%s.mo', $locale );
     1272        $uploads_dir = wp_upload_dir();
     1273
     1274        $translation_paths = array(
     1275                WP_LANG_DIR . "/{$mofile}",
     1276                BP_PLUGIN_DIR . "bp-languages/{$mofile}",
     1277                $uploads_dir['basedir'] . "/buddypress/{$mofile}",
     1278        );
     1279
     1280        foreach ( $translation_paths as $path )
     1281                load_textdomain( 'buddypress', $path );
     1282}
     1283add_action( 'bp_core_loaded', 'bp_core_load_buddypress_textdomain' );
    12831284
    12841285/**
    … …  
    13611362}
    13621363add_action( 'wp_footer', 'bp_core_print_generation_time' );
     1364
     1365/**
     1366 * Find out if there's a newer translation available for this site on translate.wordpress.org
     1367 *
     1368 * @since BuddyPress (1.8)
     1369 */
     1370function bp_core_check_for_updated_translation() {
     1371        require( buddypress()->plugin_dir  . 'bp-core/admin/bp-core-translations.php' );
     1372
     1373        $locale = BP_Translate::get_locale();
     1374        if ( 'en_US' === $locale )
     1375                return;
     1376
     1377        // No point checking if we know there's an updated translation
     1378        if ( bp_is_translation_update_pending() )
     1379                return;
     1380
     1381        $locale = BP_Translate::get_glotpress_locale();
     1382        if ( ! $locale )
     1383                return;
     1384
     1385        $url  = 'https://translate.wordpress.org/projects/buddypress/%1$s/%2$s/default/export-translations?format=mo';
     1386        $args = bp_get_translation_version() ? array( 'headers' => 'If-Modified-Since: ' . gmdate( 'D, d M Y H:i:s', bp_get_translation_version() ) . ' GMT' ) : array();
     1387
     1388        // Check version of translation on translate.wordpress.org
     1389        $response = wp_remote_head( sprintf( $url, buddypress()->glotpress_version, $locale ), $args );
     1390        if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 304 || wp_remote_retrieve_response_code( $response ) !== 200 )
     1391                return;
     1392
     1393        // An updated translation is available
     1394        bp_update_option( '_bp_translation_pending', true );
     1395}
     1396add_action( 'bp_translate_update_check', 'bp_core_check_for_updated_translation' );
Note: See TracChangeset for help on using the changeset viewer.