Changeset 8937
- Timestamp:
- 06/10/2019 02:45:10 PM (5 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/translation-row-editor.php
r8766 r8937 76 76 <div class="button-menu"> 77 77 <button type="button" class="button-menu__toggle with-tooltip" aria-label="Show contextual links"> 78 <span class="screen-reader-text">Links</span><span aria-hidden="true" class="dashicons dashicons- paperclip"></span>78 <span class="screen-reader-text">Links</span><span aria-hidden="true" class="dashicons dashicons-menu-alt"></span> 79 79 </button> 80 80 <ul class="button-menu__dropdown"> -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-sync-plugin-translations.php
r4018 r8937 14 14 15 15 /** 16 * Delete a plugin project and itstranslations.16 * Sync plugin translations. 17 17 * 18 18 * ## OPTIONS -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/class-plugin.php
r8767 r8937 5 5 use GP; 6 6 use GP_Locales; 7 use Text_Diff;8 use WP_Error;9 use WP_Http;10 use WP_Text_Diff_Renderer_inline;11 12 require_once ABSPATH . '/wp-includes/wp-diff.php' ;13 7 14 8 class Plugin { 9 10 const TM_UPDATE_EVENT = 'wporg_translate_tm_update'; 15 11 16 12 /** … … 18 14 */ 19 15 private static $instance; 16 17 /** 18 * @var array 19 */ 20 private $queue = []; 20 21 21 22 /** … … 45 46 add_action( 'gp_pre_tmpl_load', [ $this, 'pre_tmpl_load' ], 10, 2 ); 46 47 add_action( 'wporg_translate_suggestions', [ $this, 'extend_translation_suggestions' ] ); 48 49 if ( 'cli' !== PHP_SAPI ) { 50 add_action( 'gp_translation_created', [ $this, 'translation_updated' ], 3 ); 51 add_action( 'gp_translation_saved', [ $this, 'translation_updated' ], 3 ); 52 53 // DB Writes are delayed until shutdown to bulk-update the stats during imports. 54 add_action( 'shutdown', [ $this, 'schedule_tm_update' ], 3 ); 55 } 56 57 add_action( self::TM_UPDATE_EVENT, [ Translation_Memory_Client::class, 'update' ] ); 58 } 59 60 /** 61 * Adds a translation in queue when a translation was created 62 * or updated. 63 * 64 * @param \GP_Translation $translation Created/updated translation. 65 */ 66 public function translation_updated( $translation ) { 67 if ( ! $translation->user_id || 'current' !== $translation->status ) { 68 return; 69 } 70 71 $this->queue[ $translation->original_id ] = $translation->id; 72 } 73 74 /** 75 * Schedules a single event to update translation memory for new translations. 76 */ 77 public function schedule_tm_update() { 78 remove_action( 'gp_translation_created', [ $this, 'translation_updated' ], 3 ); 79 remove_action( 'gp_translation_saved', [ $this, 'translation_updated' ], 3 ); 80 81 if ( ! $this->queue ) { 82 return; 83 } 84 85 wp_schedule_single_event( time() + 60, self::TM_UPDATE_EVENT, [ 'translations' => $this->queue ] ); 47 86 } 48 87 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/class-translation-memory-client.php
r8732 r8937 3 3 namespace WordPressdotorg\GlotPress\TranslationSuggestions; 4 4 5 use GP; 5 6 use Text_Diff; 6 7 use WP_Error; … … 8 9 use WP_Text_Diff_Renderer_inline; 9 10 10 require_once ABSPATH . '/wp-includes/wp-diff.php' 11 require_once ABSPATH . '/wp-includes/wp-diff.php'; 11 12 12 13 class Translation_Memory_Client { 13 14 14 15 const API_ENDPOINT = 'https://translate.wordpress.com/api/tm/'; 16 const API_BULK_ENDPOINT = 'https://translate.wordpress.com/api/tm/-bulk'; 17 18 /** 19 * Updates translation memory with new strings. 20 * 21 * @param array $translations List of translation IDs, keyed by original ID. 22 * @return true|\WP_Error True on success, WP_Error on failure. 23 */ 24 public static function update( array $translations ) { 25 $requests = []; 26 27 foreach ( $translations as $original_id => $translation_id ) { 28 $translation = GP::$translation->get( $translation_id ); 29 30 // Check again in case the translation was changed. 31 if ( 'current' !== $translation->status ) { 32 continue; 33 } 34 35 $original = GP::$original->get( $original_id ); 36 $translation_set = GP::$translation_set->get( $translation->translation_set_id ); 37 38 $locale = $translation_set->locale; 39 if ( 'default' !== $translation_set->slug ) { 40 $locale .= '_' . $translation_set->slug; 41 } 42 43 $requests[] = [ 44 'source' => $original->fields(), 45 'translations' => [ 46 [ 47 'singular' => $translation->translation_0, 48 'plural' => $translation->translation_1, 49 'locale' => $locale, 50 ], 51 ], 52 ]; 53 } 54 55 if ( ! $requests ) { 56 return new WP_Error( 'no_translations' ); 57 } 58 59 $body = wp_json_encode( [ 60 'token' => WPCOM_TM_TOKEN, 61 'requests' => $requests, 62 ] ); 63 64 $request = wp_remote_post( 65 self::API_BULK_ENDPOINT, 66 [ 67 'timeout' => 10, 68 'user-agent' => 'WordPress.org Translate', 69 'body' => $body, 70 ] 71 ); 72 73 if ( is_wp_error( $request ) ) { 74 return $request; 75 } 76 77 if ( WP_Http::OK !== wp_remote_retrieve_response_code( $request ) ) { 78 return new WP_Error( 'response_code_not_ok' ); 79 } 80 81 $body = wp_remote_retrieve_body( $request ); 82 $result = json_decode( $body, true ); 83 84 if ( JSON_ERROR_NONE !== json_last_error() ) { 85 return new WP_Error( 'json_parse_error' ); 86 } 87 88 return $result ?: new WP_Error( 'unknown_error' ); 89 } 15 90 16 91 /** … … 22 97 */ 23 98 public static function query( string $text, string $target_locale ) { 24 if ( ! defined 99 if ( ! defined( 'WPCOM_TM_TOKEN' ) ) { 25 100 return new WP_Error( 'no_token' ); 26 101 } … … 30 105 'target' => $target_locale, 31 106 'token' => WPCOM_TM_TOKEN, 32 ] ) , self::API_ENDPOINT ); 107 'ts' => time(), 108 ] ), self::API_ENDPOINT ); 109 33 110 34 111 $request = wp_remote_get( 35 112 $url, 36 113 [ 37 'timeout' 38 'user-agent' 114 'timeout' => 2, 115 'user-agent' => 'WordPress.org Translate', 39 116 ] 40 117 ); … … 82 159 $diff = new Text_Diff( 'auto', [ [ $previous_text ], [ $text ] ] ); 83 160 $renderer = new WP_Text_Diff_Renderer_inline(); 161 84 162 return $renderer->render( $diff ); 85 163 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/js/translation-suggestions.js
r8766 r8937 7 7 'nonce': nonce 8 8 }, 9 dataType: 'json' 9 dataType: 'json', 10 cache: false, 10 11 } ); 11 12
Note: See TracChangeset
for help on using the changeset viewer.