Changeset 7079
- Timestamp:
- 04/10/2018 04:44:56 PM (7 years ago)
- Location:
- sites/trunk/wp15.wordpress.net/public_html/content/mu-plugins
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wp15.wordpress.net/public_html/content/mu-plugins/locales.php
r7060 r7079 15 15 16 16 require_once trailingslashit( dirname( __FILE__ ) ) . 'locale-detection/locale-detection.php'; 17 18 if ( ! wp_next_scheduled( 'wp15_update_pomo_files' ) ) { 19 wp_schedule_event( time(), 'hourly', 'wp15_update_pomo_files' ); 20 } 21 22 /** 23 * Update the PO/MO files for the wp15 text domain. 24 */ 25 function update_pomo_files() { 26 /* 27 * The content will probably not need to be updated after the event is over. Updating it anyway would use up API 28 * resources needlessly, and introduce the risk of overwriting the valid data with invalid data if something breaks. 29 */ 30 if ( time() >= strtotime( 'June 15, 2018' ) ) { 31 return; 32 } 33 34 $gp_api = 'https://translate.wordpress.org'; 35 $gp_project = 'meta/wp15'; 36 $localizations_dir = WP_CONTENT_DIR . '/languages/wp15'; 37 $set_response = wp_remote_get( "$gp_api/api/projects/$gp_project" ); 38 $body = json_decode( wp_remote_retrieve_body( $set_response ) ); 39 $translation_sets = isset( $body->translation_sets ) ? $body->translation_sets : false; 40 41 if ( ! $translation_sets ) { 42 trigger_error( 'Translation sets missing from response body.' ); 43 return; 44 } 45 46 $locale_status = wp_list_pluck( $translation_sets, 'percent_translated', 'wp_locale' ); 47 update_option( 'wp15_locale_status', $locale_status ); 48 49 foreach ( $translation_sets as $set ) { 50 if ( empty( $set->locale ) || empty( $set->wp_locale ) ) { 51 continue; 52 } 53 54 $po_response = wp_remote_get( "$gp_api/projects/$gp_project/{$set->locale}/default/export-translations?filters[status]=current&format=po" ); 55 $mo_response = wp_remote_get( "$gp_api/projects/$gp_project/{$set->locale}/default/export-translations?filters[status]=current&format=mo" ); 56 $po_content = wp_remote_retrieve_body( $po_response ); 57 $mo_content = wp_remote_retrieve_body( $mo_response ); 58 59 if ( ! $po_content || ! $mo_content || false === strpos( $po_content, 'Project-Id-Version: Meta - wp15.wordpress.net' ) ) { 60 trigger_error( "Invalid PO/MO content for {$set->wp_locale}." ); 61 continue; 62 } 63 64 file_put_contents( "$localizations_dir/wp15-{$set->wp_locale}.po", $po_content ); 65 file_put_contents( "$localizations_dir/wp15-{$set->wp_locale}.mo", $mo_content ); 66 } 67 } 68 69 add_filter( 'wp15_update_pomo_files', __NAMESPACE__ . '\update_pomo_files' ); 17 70 18 71 /** -
sites/trunk/wp15.wordpress.net/public_html/content/mu-plugins/miscellaneous.php
r7054 r7079 16 16 add_filter( 'map_meta_cap', __NAMESPACE__ . '\allow_css_editing', 10, 2 ); 17 17 add_filter( 'tggr_end_date', __NAMESPACE__ . '\set_tagregator_cutoff_date' ); 18 add_filter( 'wp15_update_pomo_files', __NAMESPACE__ . '\update_pomo_files' );19 18 add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\register_assets', 1 ); 20 19 add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\register_assets', 1 ); … … 22 21 23 22 add_filter( 'tggr_show_log', '__return_true' ); 24 25 if ( ! wp_next_scheduled( 'wp15_update_pomo_files' ) ) {26 wp_schedule_event( time(), 'hourly', 'wp15_update_pomo_files' );27 }28 23 29 24 … … 66 61 67 62 /** 68 * Update the PO/MO files for the wp15 text domain.69 */70 function update_pomo_files() {71 /*72 * The content will probably not need to be updated after the event is over. Updating it anyway would use up API73 * resources needlessly, and introduce the risk of overwriting the valid data with invalid data if something breaks.74 */75 if ( time() >= strtotime( 'June 15, 2018' ) ) {76 return;77 }78 79 $gp_api = 'https://translate.wordpress.org';80 $gp_project = 'meta/wp15';81 $localizations_dir = WP_CONTENT_DIR . '/languages/wp15';82 $set_response = wp_remote_get( "$gp_api/api/projects/$gp_project" );83 $body = json_decode( wp_remote_retrieve_body( $set_response ) );84 $translation_sets = isset( $body->translation_sets ) ? $body->translation_sets : false;85 86 if ( ! $translation_sets ) {87 trigger_error( 'Translation sets missing from response body.' );88 return;89 }90 91 $locale_status = wp_list_pluck( $translation_sets, 'percent_translated', 'wp_locale' );92 update_option( 'wp15_locale_status', $locale_status );93 94 foreach ( $translation_sets as $set ) {95 if ( empty( $set->locale ) || empty( $set->wp_locale ) ) {96 continue;97 }98 99 $po_response = wp_remote_get( "$gp_api/projects/$gp_project/{$set->locale}/default/export-translations?filters[status]=current&format=po" );100 $mo_response = wp_remote_get( "$gp_api/projects/$gp_project/{$set->locale}/default/export-translations?filters[status]=current&format=mo" );101 $po_content = wp_remote_retrieve_body( $po_response );102 $mo_content = wp_remote_retrieve_body( $mo_response );103 104 if ( ! $po_content || ! $mo_content || false === strpos( $po_content, 'Project-Id-Version: Meta - wp15.wordpress.net' ) ) {105 trigger_error( "Invalid PO/MO content for {$set->wp_locale}." );106 continue;107 }108 109 file_put_contents( "$localizations_dir/wp15-{$set->wp_locale}.po", $po_content );110 file_put_contents( "$localizations_dir/wp15-{$set->wp_locale}.mo", $mo_content );111 }112 }113 114 /**115 63 * Register style and script assets for later enqueueing. 116 64 */
Note: See TracChangeset
for help on using the changeset viewer.