Making WordPress.org


Ignore:
Timestamp:
06/21/2016 10:06:58 AM (9 years ago)
Author:
tellyworth
Message:

Plugin directory: include all available translations in pseudo-meta for search.

Also add some defensive code, better testing and bugfixes.

See #1691, #1692

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r3511 r3519  
    568568        remove_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ) );
    569569
    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
    574574                'fr_FR',
    575575                'es_ES',
    576576            );
     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            }
    577583
    578584            global $locale;
     
    580586
    581587            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                }
    584597
    585598                // Split up the content to translate it in sections.
    586                 $content  = '';
     599                $the_content = array();
    587600                $sections = $this->split_post_content_into_pages( get_the_content( $post_id ) );
    588601                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 );
    592609            }
    593610
    594611            $locale = $_locale;
    595612
     613        }
     614
     615        if ( is_array( $this->i18n_meta[ $post_id ] ) )
    596616            $meta = array_merge( $meta, array_keys( $this->i18n_meta[ $post_id ] ) );
    597         }
    598617
    599618        add_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ), 10, 2 );
Note: See TracChangeset for help on using the changeset viewer.