Changeset 6891
- Timestamp:
- 03/20/2018 11:54:08 PM (7 years ago)
- Location:
- sites/trunk/wp15.wordpress.net
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wp15.wordpress.net/.gitignore
r6877 r6891 7 7 config-private.php 8 8 public_html/content/cache 9 public_html/content/languages 9 10 public_html/content/upgrade 10 11 public_html/content/uploads -
sites/trunk/wp15.wordpress.net/public_html/content/mu-plugins/miscellaneous.php
r6882 r6891 9 9 */ 10 10 11 namespace WP15\ Updates;11 namespace WP15\Miscellaneous; 12 12 use DateTime; 13 13 … … 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 20 if ( ! wp_next_scheduled( 'wp15_update_pomo_files' ) ) { 21 wp_schedule_event( time(), 'hourly', 'wp15_update_pomo_files' ); 22 } 18 23 19 24 … … 54 59 return new DateTime( 'June 15, 2018' ); 55 60 } 61 62 /** 63 * Update the PO/MO files for the wp15 text domain. 64 */ 65 function update_pomo_files() { 66 $gp_api = 'https://translate.wordpress.org'; 67 $gp_project = 'meta/wp15'; 68 $localizations_dir = WP_CONTENT_DIR . '/languages/wp15'; 69 $set_response = wp_remote_get( "$gp_api/api/projects/$gp_project" ); 70 $body = json_decode( wp_remote_retrieve_body( $set_response ) ); 71 $translation_sets = isset( $body->translation_sets ) ? $body->translation_sets : false; 72 73 if ( ! $translation_sets ) { 74 trigger_error( 'Translation sets missing from response body.' ); 75 return; 76 } 77 78 foreach ( $translation_sets as $set ) { 79 if ( empty( $set->locale ) || empty( $set->wp_locale ) ) { 80 continue; 81 } 82 83 $po_response = wp_remote_get( "$gp_api/projects/$gp_project/{$set->locale}/default/export-translations?filters[status]=current&format=po" ); 84 $mo_response = wp_remote_get( "$gp_api/projects/$gp_project/{$set->locale}/default/export-translations?filters[status]=current&format=mo" ); 85 $po_content = wp_remote_retrieve_body( $po_response ); 86 $mo_content = wp_remote_retrieve_body( $mo_response ); 87 88 if ( ! $po_content || ! $mo_content || false === strpos( $po_content, "Language: {$set->wp_locale}" ) ) { 89 trigger_error( "Invalid PO/MO content for {$set->wp_locale}." ); 90 continue; 91 } 92 93 file_put_contents( "$localizations_dir/wp15-{$set->wp_locale}.po", $po_content ); 94 file_put_contents( "$localizations_dir/wp15-{$set->wp_locale}.mo", $mo_content ); 95 } 96 }
Note: See TracChangeset
for help on using the changeset viewer.