Making WordPress.org

Changeset 6198


Ignore:
Timestamp:
12/01/2017 10:50:11 AM (7 years ago)
Author:
tellyworth
Message:

Plugin directory: use the correct strings when syncing translated content to ElasticSearch.

Also reduce the translation threshold for syncing.

File:
1 edited

Legend:

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

    r6127 r6198  
    916916     * @return array
    917917     */
    918     public function sync_all_translations_to_meta( $post_id, $min_translated = 60, $skip_pfx = array('en_') ) {
     918    public function sync_all_translations_to_meta( $post_id, $min_translated = 40, $skip_pfx = array('en_') ) {
    919919
    920920        $locales_to_sync = array();
    921921        $post = get_post( $post_id );
    922922        if ( $post ) {
    923             $translations = Plugin_I18n::find_all_translations_for_plugin( $post->post_name, 'stable-readme', $min_translated ); // at least $min_translated % translated
     923            $translations = Plugin_I18n::instance()->find_all_translations_for_plugin( $post->post_name, 'stable-readme', $min_translated ); // at least $min_translated % translated
    924924            if ( $translations ) {
    925925                // Eliminate translations that start with unwanted prefixes, so we don't waste space on near-duplicates like en_AU, en_CA etc.
     
    952952    public function sync_translation_to_meta( $post_id, $_locale ) {
    953953        global $locale;
     954
    954955        $old_locale = $locale;
     956        // Keep track of the original untranslated strings
     957        $orig_title = get_the_title( $post_id );
     958        $orig_excerpt = get_the_excerpt( $post_id );
     959        $orig_content = get_post_field( 'post_content', $post_id );
    955960        $locale = $_locale;
    956961
     
    958963        // There is a bug here, in that no attempt is made to remove old meta values for translations that do not have new translations.
    959964
    960         $the_title = Plugin_I18n::instance()->translate( 'title', get_the_title( $post_id ), [ 'post_id' => $post_id ] );
    961         if ( $the_title && $the_title != get_the_title( $post_id ) ) {
     965        $the_title = Plugin_I18n::instance()->translate( 'title', $orig_title, [ 'post_id' => $post_id ] );
     966        if ( $the_title && $the_title != $orig_title ) {
    962967            update_post_meta( $post_id, 'title_' . $locale, $the_title );
    963968        }
    964969
    965         $the_excerpt = $this->translate_post_excerpt( get_the_excerpt( $post_id ), $post_id );
    966         if ( $the_excerpt && $the_excerpt != get_the_excerpt( $post_id ) ) {
     970        $the_excerpt = $this->translate_post_excerpt( $orig_excerpt, $post_id );
     971        if ( $the_excerpt && $the_excerpt != $orig_excerpt ) {
    967972            update_post_meta( $post_id, 'excerpt_' . $locale, $the_excerpt );
    968973        }
     
    970975        // Split up the content to translate it in sections.
    971976        $the_content = array();
    972         $sections = $this->split_post_content_into_pages( get_the_content( $post_id ) );
     977        $sections = $this->split_post_content_into_pages( $orig_content );
    973978        foreach ( $sections as $section => $section_content ) {
    974979            $translated_section = $this->translate_post_content( $section_content, $section, $post_id );
    975980            if ( $translated_section && $translated_section != $section_content ) {
    976                 $the_content[] = $translated_section;
     981                // ES expects the section delimiters to still be present
     982                $the_content[ $section ] = "<!--section={$section}-->\n" . $translated_section;
    977983            }
    978984        }
    979         if ( !empty( $the_content ) )
     985
     986        if ( !empty( $the_content ) ) {
    980987            update_post_meta( $post_id, 'content_' . $locale, implode( $the_content ) );
     988        }
    981989
    982990        $locale = $old_locale;
Note: See TracChangeset for help on using the changeset viewer.