Making WordPress.org

Changeset 5982


Ignore:
Timestamp:
10/01/2017 09:32:59 AM (7 years ago)
Author:
ocean90
Message:

Plugin Directory: Short-circuit Plugin_I18n::translate_gp_original() if the content to translate is the same as the original.

Fixes #3173.

File:
1 edited

Legend:

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

    r5864 r5982  
    407407     */
    408408    public function translate_gp_original( $original, $translation, $content ) {
    409         $original = preg_quote( $original, '/' );
    410 
    411         if ( false === strpos( $content, '<' ) ) {
    412             // Don't use $translation, it may contain backreference-like characters.
    413             $content = preg_replace( "/\b{$original}\b/", '___TRANSLATION___', $content );
     409        if ( $original === $content ) {
     410            $content = $translation;
    414411        } else {
    415             // Don't use $translation, it may contain backreference-like characters.
    416             $content = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", '${1}___TRANSLATION___${3}', $content );
    417         }
    418 
    419         $content = str_replace( '___TRANSLATION___', $translation, $content );
     412            $original = preg_quote( $original, '/' );
     413
     414            if ( false === strpos( $content, '<' ) ) {
     415                // Don't use $translation, it may contain backreference-like characters.
     416                $content = preg_replace( "/\b{$original}\b/", '___TRANSLATION___', $content );
     417            } else {
     418                // Don't use $translation, it may contain backreference-like characters.
     419                $content = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", '${1}___TRANSLATION___${3}', $content );
     420            }
     421
     422            $content = str_replace( '___TRANSLATION___', $translation, $content );
     423        }
    420424
    421425        return $content;
Note: See TracChangeset for help on using the changeset viewer.