Making WordPress.org

Changeset 14814


Ignore:
Timestamp:
04/14/2026 08:37:26 AM (4 weeks ago)
Author:
dd32
Message:

Plugin Directory: Fix edge-cases that caused translated readme strings not rendering on localised plugin pages.

This was primarily nested lists, but also headers outside of the expected range.
Some additional matching around whitespace is included for resilience.

Props dd32, masteradhoc.
Closes https://github.com/WordPress/wordpress.org/pull/605.
Fixes https://github.com/WordPress/wordpress.org/issues/601.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
1 added
2 edited

Legend:

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

    r12176 r14814  
    394394            $content = $marker;
    395395        } else {
    396             $original = preg_quote( $original, '/' );
    397 
    398             if ( false === strpos( $content, '<' ) ) {
     396            $original = preg_quote( trim( $original ), '/' );
     397
     398            if ( ! str_contains( $content, '<' ) ) {
    399399                $content = preg_replace( "/\b{$original}\b/", $marker, $content );
    400400            } else {
    401                 $content = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", "\${1}{$marker}\${3}", $content );
     401                $content = preg_replace( "/(<([a-z0-9]*)\b[^>]*>)\s*{$original}\s*(<\/\\2>)/m", "\${1}{$marker}\${3}", $content );
     402
     403                // Nested lists: match <li>STRING<ul> or <li>STRING<ol>.
     404                if ( ! str_contains( $content, $marker ) ) {
     405                    $content = preg_replace( "/(<li\b[^>]*>)\s*{$original}\s*(<[uo]l\b[^>]*>)/m", "\${1}{$marker}\${2}", $content );
     406                }
    402407            }
    403408        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-readme-import.php

    r14778 r14814  
    8989        foreach ( $readme->sections as $section_key => $section_text ) {
    9090           
    91             if ( preg_match_all( '~<(h[3-4]|dt)[^>]*>([^<].+)</\1>~', $section_text, $matches ) ) {
     91            if ( preg_match_all( '~<(h[1-6]|dt)[^>]*>([^<].+)</\1>~', $section_text, $matches ) ) {
    9292                if ( ! empty( $matches[2] ) ) {
    9393                    foreach ( $matches[2] as $text ) {
     
    9797                        }
    9898
    99                         $section_strings = $this->handle_translator_comment( $section_strings, $text, "{$section_key} header" );
     99                        $section_strings = $this->handle_translator_comment( $section_strings, trim( $text ), "{$section_key} header" );
    100100                        if ( 'changelog' === $section_key ) {
    101101                            $str_priorities[ $text ] = -1;
     
    108108                if ( ! empty( $matches[1] ) ) {
    109109                    foreach ( $matches[1] as $text ) {
    110                         $section_strings = $this->handle_translator_comment( $section_strings, $text, "{$section_key} list item" );
     110                        $section_strings = $this->handle_translator_comment( $section_strings, trim( $text ), "{$section_key} list item" );
    111111                        if ( 'changelog' === $section_key ) {
    112112                            $str_priorities[ $text ] = -1;
Note: See TracChangeset for help on using the changeset viewer.