Changeset 3519
- Timestamp:
- 06/21/2016 10:06:58 AM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r3511 r3519 568 568 remove_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ) ); 569 569 570 if ( $post_id <= 200) {571 572 // This should probably be a list of available translations for the plugin readme.573 $locales_to_sync = array(570 if ( empty( $this->i18n_meta[ $post_id ] ) ) { 571 572 $locales_to_sync = array( 573 // Default locales to translate, just in case we can't determine the available ones 574 574 'fr_FR', 575 575 'es_ES', 576 576 ); 577 $post = get_post( $post_id ); 578 if ( $post ) { 579 $translations = Plugin_I18n::find_all_translations_for_plugin( $post->post_name, 'stable-readme', 10 ); // at least 10% translated 580 if ( $translations ) 581 $locales_to_sync = $translations; 582 } 577 583 578 584 global $locale; … … 580 586 581 587 foreach ( $locales_to_sync as $locale ) { 582 $this->i18n_meta[ $post_id ][ 'title_' . $locale ] = $this->translate_post_title( get_the_title( $post_id ), $post_id ); 583 $this->i18n_meta[ $post_id ][ 'excerpt_' . $locale ] = $this->translate_post_excerpt( get_the_excerpt( $post_id ), $post_id ); 588 $the_title = $this->translate_post_title( get_the_title( $post_id ), $post_id ); 589 if ( $the_title && $the_title != get_the_title( $post_id ) ) { 590 $this->i18n_meta[ $post_id ][ 'title_' . $locale ] = $the_title; 591 } 592 593 $the_excerpt = $this->translate_post_excerpt( get_the_excerpt( $post_id ), $post_id ); 594 if ( $the_excerpt && $the_excerpt != get_the_excerpt( $post_id ) ) { 595 $this->i18n_meta[ $post_id ][ 'excerpt_' . $locale ] = $the_excerpt; 596 } 584 597 585 598 // Split up the content to translate it in sections. 586 $ content = '';599 $the_content = array(); 587 600 $sections = $this->split_post_content_into_pages( get_the_content( $post_id ) ); 588 601 foreach ( $sections as $section => $section_content ) { 589 $content .= $this->translate_post_content( $section_content, $section, $post_id ); 590 } 591 $this->i18n_meta[ $post_id ][ 'content_' . $locale ] = $content; 602 $translated_section = $this->translate_post_content( $section_content, $section, $post_id ); 603 if ( $translated_section && $translated_section != $section_content ) { 604 $the_content[] = $translated_section; 605 } 606 } 607 if ( !empty( $the_content ) ) 608 $this->i18n_meta[ $post_id ][ 'content_' . $locale ] = implode( $the_content ); 592 609 } 593 610 594 611 $locale = $_locale; 595 612 613 } 614 615 if ( is_array( $this->i18n_meta[ $post_id ] ) ) 596 616 $meta = array_merge( $meta, array_keys( $this->i18n_meta[ $post_id ] ) ); 597 }598 617 599 618 add_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ), 10, 2 ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php
r3511 r3519 420 420 return $content; 421 421 } 422 423 /** 424 * Returns a list of translation locales for a given plugin slug and branch. 425 * 426 * @param string $slug Plugin slug. 427 * @param string $branch Branch - 'stable-readme' for example. 428 * @param string $min_percent Only return locales where percent_translated is >= this value. 429 * @return array 430 */ 431 public function find_all_translations_for_plugin( $slug, $branch, $min_percent = 0 ) { 432 433 // This naively hits the API. It could probably be re-written to query the DB instead. 434 $api_url = esc_url_raw( 'https://translate.wordpress.org/api/projects/wp-plugins/' . $slug . '/' . $branch, array( 'https' ) ); 435 436 $out = array(); 437 if ( $json = file_get_contents( $api_url ) ) { 438 if ( $data = json_decode( $json ) ) { 439 if ( isset( $data->translation_sets ) ) { 440 foreach ( $data->translation_sets as $translation ) { 441 if ( $translation->percent_translated >= $min_percent ) 442 $out[] = $translation->wp_locale; 443 } 444 } 445 } 446 } 447 448 return $out; 449 } 450 422 451 }
Note: See TracChangeset
for help on using the changeset viewer.