Changeset 5218 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php
- Timestamp:
- 03/30/2017 09:44:49 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php
r4764 r5218 431 431 */ 432 432 public function find_all_translations_for_plugin( $slug, $branch, $min_percent = 0 ) { 433 $post = Plugin_Directory::get_plugin_post( $slug ); 434 435 return wp_filter_object_list( $this->get_locales( $post, $branch, $min_percent ), null, null, 'wp_locale' ); 436 } 437 438 /** 439 * Returns a list of locale objects for a given plugin slug and branch. 440 * 441 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 442 * @param string $branch Optional. Branch - 'stable-readme' for example. Default: 'stable'. 443 * @param int $min_percent Optional. Only return locales where percent_translated is >= this value. 444 * Default: 95. 445 * @return array 446 */ 447 public function get_locales( $post = null, $branch = 'stable', $min_percent = 95 ) { 448 $post = get_post( $post ); 433 449 434 450 // This naively hits the API. It could probably be re-written to query the DB instead. 435 $api_url = esc_url_raw( 'https://translate.wordpress.org/api/projects/wp-plugins/' . $ slug. '/' . $branch, array( 'https' ) );436 437 $ out= array();438 $http = new \WP_Http();439 $result = $http->request( $api_url );451 $api_url = esc_url_raw( 'https://translate.wordpress.org/api/projects/wp-plugins/' . $post->post_name . '/' . $branch, array( 'https' ) ); 452 453 $locales = array(); 454 $http = new \WP_Http(); 455 $result = $http->request( $api_url ); 440 456 441 457 if ( ! is_wp_error( $result ) ) { 442 458 $data = json_decode( $result['body'] ); 443 459 444 if ( $data && isset( $data->translation_sets ) ) { 445 foreach ( $data->translation_sets as $translation ) { 446 if ( $translation->percent_translated >= $min_percent ) { 447 $out[] = $translation->wp_locale; 448 } 449 } 460 if ( ! empty( $data->translation_sets ) ) { 461 $locales = array_filter( $data->translation_sets, function( $locale ) use ( $min_percent ) { 462 return $locale->percent_translated >= $min_percent; 463 } ); 450 464 } 451 465 } 452 466 453 return $ out;467 return $locales; 454 468 } 455 469 }
Note: See TracChangeset
for help on using the changeset viewer.