Making WordPress.org

Changeset 10683


Ignore:
Timestamp:
02/17/2021 03:29:43 AM (4 years ago)
Author:
dd32
Message:

Translate: Auto-correct spaced placeholders, common with machine translations.

This replaces % 1 $ s with %1$s in translations if it corrects the translation.

Machine translations aren't always wanted, but in many cases simply re-submitting the translation with the fixed placeholder is all that's done, this just reduces the amount of warnings generated, allowing translators to focus on the language content of the string.

See #5563, #5154.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-fixer/wporg-gp-translation-fixer.php

    r9889 r10683  
    6666                        // Try replacing unicode percent signs with a ascii percent sign.
    6767                        $translation = preg_replace( '!(﹪|%)((\d+\$(?:\d+)?)?[bcdefgosuxEFGX])!', '%$2', $translation );
     68
     69                        // Try replacing spaced translation type with no spaces `% 1 $ s` (Machine translated text)
     70                        $translation = preg_replace_callback(
     71                            '!%\s?(\d+\s?\$(?:\d+)?)?\s?[bcdefgosuxEFGX]!',
     72                            function( $m ) {
     73                                return str_replace( ' ', '', $m[0] );
     74                            },
     75                            $translation
     76                        );
     77
    6878                        break;
    6979                }
Note: See TracChangeset for help on using the changeset viewer.