Making WordPress.org

Changeset 9814


Ignore:
Timestamp:
05/02/2020 10:50:07 AM (7 years ago)
Author:
ocean90
Message:

Translate: Split multiple translator comments for an original into separate lines.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/class-plugin.php

    r9555 r9814  
    4646                add_filter( 'gp_translation_row_template_more_links', array( $this, 'add_consistency_tool_link' ), 10, 5 );
    4747                add_filter( 'gp_translation_prepare_for_save', array( $this, 'apply_capital_P_dangit' ), 10, 2 );
     48                add_filter( 'gp_original_extracted_comments', array( $this, 'format_translator_commments' ), 5 );
    4849
    4950                // Cron.
    … …  
    6667                        $this->register_cli_commands();
    6768                }
     69        }
     70
     71        /**
     72         * Splits multiple translator comments for an original into separate lines.
     73         */
     74        public function format_translator_commments( $comments ) {
     75                $comment_parts = preg_split( '#(^|\n)translators: #i', $comments, 0, PREG_SPLIT_NO_EMPTY );
     76                if ( ! $comment_parts ) {
     77                        return $comments;
     78                }
     79
     80                return implode( '<br/>', $comment_parts );
    6881        }
    6982
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/translation-row-editor.php

    r9813 r9814  
    107107                                                <?php endif; ?>
    108108                                                <?php if ( $translation->extracted_comments ) :
    109                                                         $comments = trim( preg_replace( '/^translators:/ ', '', $translation->extracted_comments ) );
    110109                                                        ?>
    111110                                                        <details open class="source-details__comment">
    112111                                                                <summary><?php _e( 'Comment', 'glotpress' ); ?></summary>
    113                                                                 <p><?php echo make_clickable( esc_translation( $comments ) ); ?></p>
     112                                                                <p>
     113                                                                        <?php
     114                                                                        /**
     115                                                                         * Filters the extracted comments of an original.
     116                                                                         *
     117                                                                         * @param string         $extracted_comments Extracted comments of an original.
     118                                                                         * @param GP_Translation $translation        Translation object.
     119                                                                         */
     120                                                                        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
     121                                                                        echo apply_filters( 'gp_original_extracted_comments', $translation->extracted_comments, $translation );
     122                                                                        ?>
     123                                                                </p>
    114124                                                        </details>
    115125                                                <?php endif; ?>
Note: See TracChangeset for help on using the changeset viewer.