Make WordPress Core

Ticket #42818: 42818.2.diff

File 42818.2.diff, 4.8 KB (added by soulseekah, 7 years ago)
  • tools/i18n/not-gettexted.php

    diff --git a/tools/i18n/not-gettexted.php b/tools/i18n/not-gettexted.php
    index e8ae2c3..e896d71 100644
    a b class NotGettexted { 
    6868
    6969
    7070        function make_string_aggregator($global_array_name, $filename) {
    71                 $a = $global_array_name;
    72                 return create_function('$string, $comment_id, $line_number', 'global $'.$a.'; $'.$a.'[] = array($string, $comment_id, '.var_export($filename, true).', $line_number);');
     71                return array( new NotGettexted_Aggregator( $global_array_name, $filename ), 'aggregate' );
    7372        }
    7473
    7574        function make_mo_replacer($global_mo_name) {
    76                 $m = $global_mo_name;
    77                 return create_function('$token, $string', 'global $'.$m.'; return var_export($'.$m.'->translate($string), true);');
     75                return array( new NotGettexted_Replacer( $global_mo_name ), 'replace' );
    7876        }
    7977
    8078        function walk_tokens(&$tokens, $string_action, $other_action, $register_action=null) {
    class NotGettexted { 
    222220        }
    223221}
    224222
     223class NotGettexted_Aggregator {
     224        private $global_array_name;
     225        private $filename;
     226
     227        public function __construct( $global_array_name, $filename ) {
     228                $this->global_array_name = $global_array_name;
     229                $this->filename = $filename;
     230        }
     231
     232        public function aggregate( $string, $comment_id, $line_number ) {
     233                if ( ! is_array( $GLOBALS[ $this->global_array_name ] ) ) {
     234                        $GLOBALS[ $this->global_array_name ] = array();
     235                }
     236                $GLOBALS[ $this->global_array_name ] []= array( $string, $comment_id, $this->filename, $line_number );
     237        }
     238}
     239
     240class NotGettexted_Replacer {
     241        private $global_mo_name;
     242
     243        public function __construct( $global_mo_name ) {
     244                $this->global_mo_name = $global_mo_name;
     245        }
     246
     247        public function replace( $token, $string ) {
     248                if ( ! empty( $GLOBALS[ $this->global_mo_name ] ) ) {
     249                        $mo = &$GLOBALS[ $this->global_mo_name ];
     250                        if ( is_object( $mo ) && method_exists( $mo, 'translate' ) ) {
     251                                return var_export( $mo->translate( $string ), true );
     252                        }
     253                }
     254        }
     255}
     256
    225257// run the CLI only if the file
    226258// wasn't included
    227259$included_files = get_included_files();
  • tools/i18n/t/NotGettextedTest.php

    diff --git a/tools/i18n/t/NotGettextedTest.php b/tools/i18n/t/NotGettextedTest.php
    index 22ac7b9..69b3e70 100644
    a b require_once dirname( dirname( __FILE__ ) ) . '/not-gettexted.php'; 
    1010
    1111class NotGettextedTest extends PHPUnit_Framework_TestCase {
    1212
    13         function __construct() {
     13        function setUp() {
     14                parent::setUp();
    1415                $this->ng = new NotGettexted;
    1516        }
    1617
  • tools/i18n/t/data/not-gettexted-0.po

    diff --git a/tools/i18n/t/data/not-gettexted-0.mo b/tools/i18n/t/data/not-gettexted-0.mo
    index 4042fb0..90cbd1b 100644
    Binary files a/tools/i18n/t/data/not-gettexted-0.mo and b/tools/i18n/t/data/not-gettexted-0.mo differ
    diff --git a/tools/i18n/t/data/not-gettexted-0.po b/tools/i18n/t/data/not-gettexted-0.po
    index 606ac7e..326184c 100644
    a b msgstr "" 
    1111
    1212#. Not gettexted string WP_I18N_CONFIG
    1313#: not-gettext-0.php:11
    14 msgid " There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can create a <code>wp-config.php</code> file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.</p><p><a href='%s' class='button'>Create a Configuration File</a>"
    15 msgstr "Translation: There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can create a <code>wp-config.php</code> file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.</p><p><a href='%s' class='button'>Create a Configuration File</a>"
     14msgid " There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='https://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can create a <code>wp-config.php</code> file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.</p><p><a href='%s' class='button'>Create a Configuration File</a>"
     15msgstr "Translation: There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='https://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can create a <code>wp-config.php</code> file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.</p><p><a href='%s' class='button'>Create a Configuration File</a>"
    1616
    1717#. Not gettexted string WP_I18N_ERROR
    1818#: not-gettext-0.php:11