WordPress.org

Making WordPress.org

Changeset 10352


Ignore:
Timestamp:
10/06/2020 07:33:26 AM (14 months ago)
Author:
dd32
Message:

Plugin Directory: Ensure that all locale translated text gets synced to postmeta so as to get synced to Jetpack ElasticSearch.

See #1496.

File:
1 edited

Legend:

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

    r10340 r10352  
    10671067     * Fetch all translated content for a given post, and push it into postmeta.
    10681068     *
    1069      * @global string $locale Current locale.
    1070      *
    1071      * @param int $post_id    Post ID to update.
     1069     * @param int|string|WP_Post $plugin Plugin to update.
    10721070     * @param int $min_translated Translations below this % threshold will not be synced to meta, to save space.
    10731071     * @return array
    10741072     */
    1075     public function sync_all_translations_to_meta( $post_id, $min_translated = 40, $skip_pfx = array( 'en_' ) ) {
     1073    public function sync_all_translations_to_meta( $plugin, $min_translated = 40, $skip_pfx = array( 'en_' ) ) {
    10761074
    10771075        $locales_to_sync = array();
    1078         $post            = get_post( $post_id );
     1076        $post            = self::get_plugin_post( $plugin );
    10791077        if ( $post ) {
    10801078            $project = 'stable-readme';
     
    10821080                $project = 'dev-readme';
    10831081            }
     1082
    10841083            $translations = Plugin_I18n::instance()->find_all_translations_for_plugin( $post->post_name, $project, $min_translated ); // at least $min_translated % translated
    10851084            if ( $translations ) {
     
    10981097        if ( count( $locales_to_sync ) > 0 ) {
    10991098            foreach ( $locales_to_sync as $locale ) {
    1100                 $this->sync_translation_to_meta( $post_id, $locale );
     1099                $this->sync_translation_to_meta( $post->ID, $locale );
    11011100            }
    11021101        }
     
    11071106    /**
    11081107     * Fetch translated content for a given post and locale, and push it into postmeta.
    1109      *
    1110      * @global string $locale Current locale.
    11111108     *
    11121109     * @param int    $post_id    Post ID to update.
     
    11211118        // Update postmeta values for the translated title, excerpt, and content, if they are available and different from the originals.
    11221119        // There is a bug here, in that no attempt is made to remove old meta values for translations that do not have new translations.
    1123         $the_title = Plugin_I18n::instance()->translate( 'title', $orig_title, [ 'post_id' => $post_id ] );
     1120        $the_title = Plugin_I18n::instance()->translate( 'title', $orig_title, [ 'post_id' => $post_id, 'locale' => $locale ] );
    11241121        if ( $the_title && $the_title != $orig_title ) {
    11251122            update_post_meta( $post_id, 'title_' . $locale, $the_title );
    11261123        }
    11271124
    1128         $the_excerpt = $this->translate_post_excerpt( $orig_excerpt, $post_id );
     1125        $the_excerpt =  Plugin_I18n::instance()->translate( 'excerpt', $orig_excerpt, [ 'post_id' => $post_id, 'locale' => $locale ] );
    11291126        if ( $the_excerpt && $the_excerpt != $orig_excerpt ) {
    11301127            update_post_meta( $post_id, 'excerpt_' . $locale, $the_excerpt );
     
    11351132        $sections    = $this->split_post_content_into_pages( $orig_content );
    11361133        foreach ( $sections as $section => $section_content ) {
    1137             $translated_section = $this->translate_post_content( $section_content, $section, $post_id );
     1134            $translated_section = Plugin_I18n::instance()->translate( $section, $section_content, [ 'post_id' => $post_id, 'locale' => $locale ] );
    11381135            if ( $translated_section && $translated_section != $section_content ) {
    11391136                // ES expects the section delimiters to still be present
     
    11491146        $existing_translated_titles = array_unique( get_post_meta( $post_id, 'block_title_' . $locale ) );
    11501147        foreach ( array_unique( get_post_meta( $post_id, 'block_title' ) ) as $block_title ) {
    1151             $translated_title = Plugin_I18n::instance()->translate( 'block_title:' . md5( $block_title ), $block_title, [ 'post_id' => $post_id ] );
     1148            $translated_title = Plugin_I18n::instance()->translate( 'block_title:' . md5( $block_title ), $block_title, [ 'post_id' => $post_id, 'locale' => $locale ] );
    11521149
    11531150            if ( $translated_title == $block_title ) {
Note: See TracChangeset for help on using the changeset viewer.