Making WordPress.org

Changeset 10119


Ignore:
Timestamp:
08/05/2020 04:25:59 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Search: Store translated block titles for searching.

See [10117].

File:
1 edited

Legend:

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

    r10116 r10119  
    11071107         * @param string $locale  Locale to translate.
    11081108         */
    1109         public function sync_translation_to_meta( $post_id, $_locale ) {
    1110                 global $locale;
    1111 
    1112                 $old_locale = $locale;
     1109        public function sync_translation_to_meta( $post_id, $locale ) {
    11131110                // Keep track of the original untranslated strings
    11141111                $orig_title   = get_the_title( $post_id );
    11151112                $orig_excerpt = get_the_excerpt( $post_id );
    11161113                $orig_content = get_post_field( 'post_content', $post_id );
    1117                 $locale       = $_locale;
    11181114
    11191115                // Update postmeta values for the translated title, excerpt, and content, if they are available and different from the originals.
    … …  
    11441140                }
    11451141
    1146                 $locale = $old_locale;
     1142                // Translate Block Titles. A bit more complicated as there's multiple postmeta values.
     1143                $existing_translated_titles = array_unique( get_post_meta( $post_id, 'block_title_' . $locale ) );
     1144                foreach ( array_unique( get_post_meta( $post_id, 'block_title' ) ) as $block_title ) {
     1145                        $translated_title = Plugin_I18n::instance()->translate( 'block_title:' . md5( $block_title ), $block_title, [ 'post_id' => $post_id ] );
     1146
     1147                        if ( $translated_title == $block_title ) {
     1148                                continue;
     1149                        }
     1150
     1151                        if ( false !== ( $pos = array_search( $translated_title, $existing_translated_titles, true ) ) ) {
     1152                                // If translation is meta'd, skip
     1153                                unset( $existing_translated_titles[ $pos ] );
     1154                        } else {
     1155                                // If tranlation is unknown, add it.
     1156                                add_post_meta( $post_id, 'block_title_' . $locale, $translated_title );
     1157                        }
     1158                }
     1159                // Delete any unknown translations.
     1160                foreach ( $existing_translated_titles as $block_title ) {
     1161                        delete_post_meta( $post_id, 'block_title_' . $locale, $block_title );
     1162                }
    11471163        }
    11481164
Note: See TracChangeset for help on using the changeset viewer.