Skip to:
Content

BuddyPress.org

Changeset 7097


Ignore:
Timestamp:
05/22/2013 11:24:01 PM (12 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.

Location:
trunk
Files:
1 added
4 edited

Legend:

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

    r6935 r7097  
    9494     */
    9595    private function includes() {
    96         require( $this->admin_dir . 'bp-core-actions.php'    );
    97         require( $this->admin_dir . 'bp-core-settings.php'   );
    98         require( $this->admin_dir . 'bp-core-functions.php'  );
    99         require( $this->admin_dir . 'bp-core-components.php' );
    100         require( $this->admin_dir . 'bp-core-slugs.php'      );
     96        require( $this->admin_dir . 'bp-core-actions.php'      );
     97        require( $this->admin_dir . 'bp-core-settings.php'     );
     98        require( $this->admin_dir . 'bp-core-functions.php'    );
     99        require( $this->admin_dir . 'bp-core-components.php'   );
     100        require( $this->admin_dir . 'bp-core-slugs.php'        );
     101        require( $this->admin_dir . 'bp-core-translations.php' );
    101102    }
    102103
  • 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' );
  • trunk/bp-core/bp-core-options.php

    r6971 r7097  
    6464        // The ID for the current theme package.
    6565        '_bp_theme_package_id'            => 'legacy',
     66
     67        // Timestamp of the the current translation from translate.wordpress.org
     68        '_bp_translation_version'         => 0,
     69
     70        // Is there a more recent translation available on translate.wordpress.org?
     71        '_bp_translation_pending'         => false,
    6672
    6773        /** Groups ************************************************************/
     
    537543    return apply_filters( 'bp_get_theme_package_id', bp_get_option( '_bp_theme_package_id', $default ) );
    538544}
     545
     546/**
     547 * Get the timestamp of the the current translation from translate.wordpress.org
     548 *
     549 * @param int $default Optional; default value 0.
     550 * @return int Unix timestamp
     551 * @since BuddyPress (1.8)
     552 */
     553function bp_get_translation_version( $default = 0 ) {
     554    return apply_filters( 'bp_get_translation_version', (int) bp_get_option( '_bp_translation_version', $default ) );
     555}
     556
     557/**
     558 * Does translate.wordpress.org have a more recent translation available on translate.wordpress.org?
     559 *
     560 * @param bool $default Optional; defaults to false.
     561 * @return bool
     562 * @see BP_Translate->check_for_updated_translation()
     563 * @since BuddyPress (1.8)
     564 */
     565function bp_is_translation_update_pending( $default = false ) {
     566    return apply_filters( 'bp_is_translation_update_pending', (bool) bp_get_option( '_bp_translation_pending', $default ) );
     567}
  • trunk/bp-loader.php

    r7013 r7097  
    281281        $this->version    = '1.8-bleeding-7013';
    282282        $this->db_version = 6080;
     283        $this->glotpress_version = 'dev';
    283284
    284285        /** Loading ***********************************************************/
Note: See TracChangeset for help on using the changeset viewer.