Changeset 10063
- Timestamp:
- 07/11/2020 03:57:12 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-make-core-pot.php
r9210 r10063 3 3 namespace WordPressdotorg\GlotPress\Customizations\CLI; 4 4 5 use Gettext\Extractors\Po; 6 use Gettext\Translations; 5 7 use GP; 6 8 use WP_CLI; 7 9 use WP_CLI\Utils; 8 10 use WP_CLI_Command; 11 use WP_CLI\I18n\PotGenerator; 9 12 10 13 class Make_Core_Pot extends WP_CLI_Command { … … 57 60 58 61 $file_comment = sprintf( 59 'Copyright (C) %s by the contributors\nThis file is distributed under the same license as the WordPress package.',62 "Copyright (C) %s by the contributors\nThis file is distributed under the same license as the WordPress package.", 60 63 date( 'Y' ) 61 64 ); 65 PotGenerator::setCommentBeforeHeaders( $file_comment ); 62 66 63 67 $command_args = [ … … 72 76 'package-name' => self::PACKAGE_NAME, 73 77 'headers' => $headers, 74 'file-comment' => $file_comment,78 'file-comment' => '', 75 79 'skip-js' => true, 76 80 'skip-audit' => true, … … 108 112 'wp-includes/js/codemirror/*', 109 113 'wp-includes/js/crop/*', 114 'wp-includes/js/dist/vendor/*', 110 115 'wp-includes/js/imgareaselect/*', 111 116 'wp-includes/js/jcrop/*', … … 115 120 'wp-includes/js/swfupload/*', 116 121 'wp-includes/js/thickbox/*', 122 'wp-includes/js/clipboard.js', 123 'wp-includes/js/colorpicker.js', 124 'wp-includes/js/hoverIntent.js', 125 'wp-includes/js/json2.js', 126 'wp-includes/js/swfobject.js', 117 127 'wp-includes/js/tw-sack.js', 128 'wp-includes/js/twemoji.js', 129 'wp-includes/js/underscore.js', 118 130 ]; 119 131 … … 134 146 'package-name' => self::PACKAGE_NAME, 135 147 'headers' => $headers, 136 'file-comment' => $file_comment,148 'file-comment' => '', 137 149 'skip-audit' => true, 138 150 'ignore-domain' => true, … … 160 172 'package-name' => self::PACKAGE_NAME, 161 173 'headers' => $headers, 162 'file-comment' => $file_comment,174 'file-comment' => '', 163 175 'skip-js' => true, 164 176 'skip-audit' => true, … … 184 196 $admin_exclude = [ 185 197 'wp-admin/includes/continents-cities.php', 186 'editor.min.js', // Explicitly excluded as it's causing a memory leak: https://github.com/wp-cli/i18n-command/issues/185187 198 // External libraries. 188 199 'wp-admin/includes/class-ftp*', … … 190 201 ]; 191 202 203 // Explicitly exclude minified JavaScript files as they may 204 // cause memory leaks: https://github.com/wp-cli/i18n-command/issues/185. 205 $admin_min_js = array_map( 'basename', glob( $this->source . '/wp-admin/js/*.min.js' ) ); 206 $admin_exclude = array_merge( $admin_exclude, $admin_min_js ); 207 192 208 $admin_exclude = array_merge( $admin_exclude, $admin_network_files ); 193 209 … … 203 219 'include' => 'wp-admin/*', 204 220 'merge' => $hello_dolly_pot, 205 'subtract' => $this->destination . '/wordpress.pot', 206 'package-name' => self::PACKAGE_NAME, 207 'headers' => $headers, 208 'file-comment' => $file_comment, 221 'package-name' => self::PACKAGE_NAME, 222 'headers' => $headers, 223 'file-comment' => '', 209 224 'skip-audit' => true, 210 225 'ignore-domain' => true, … … 219 234 unlink( $hello_dolly_pot ); 220 235 236 $this->merge_pot( $this->destination . '/wordpress.pot', $this->destination . '/wordpress-admin.pot' ); 237 221 238 // Admin Network. 222 239 $command_args = [ … … 229 246 $command_assoc_args = [ 230 247 'include' => implode( ',', $admin_network_files ), 231 'subtract' => sprintf( '%1$s/wordpress.pot,%1$s/wordpress-admin.pot', $this->destination ), 232 'package-name' => self::PACKAGE_NAME, 233 'headers' => $headers, 234 'file-comment' => $file_comment, 248 'package-name' => self::PACKAGE_NAME, 249 'headers' => $headers, 250 'file-comment' => '', 235 251 'skip-js' => true, // TODO: No use of wp.i18n, yet. 236 252 'skip-audit' => true, … … 239 255 240 256 WP_CLI::run_command( $command_args, $command_assoc_args ); 257 258 $this->merge_pot( $this->destination . '/wordpress.pot', $this->destination . '/wordpress-admin-network.pot' ); 259 $this->merge_pot( $this->destination . '/wordpress-admin.pot', $this->destination . '/wordpress-admin-network.pot' ); 241 260 } 242 261 … … 254 273 return preg_match( '/\$wp_version\s*=\s*\'(.*?)\';/', file_get_contents( $version_php ), $matches ) ? $matches[1] : false; 255 274 } 275 276 /** 277 * Merges duplicate originals of two POT files. 278 * 279 * Preserves the references and comments of each original. 280 * 281 * @param string $to_file Path to the POT file where duplicates should be merged into. 282 * @param string $from_file Path to the POT file where duplicates should be extracted from. 283 */ 284 private function merge_pot( $to_file, $from_file ) { 285 $to = new Translations(); 286 Po::fromFile( $to_file, $to ); 287 $from = new Translations(); 288 Po::fromFile( $from_file, $from ); 289 290 foreach ( $to as $original ) { 291 // Check for duplicate. 292 $existing = $from->find( $original ); 293 if ( ! $existing ) { 294 continue; 295 } 296 297 // Merge. 298 $original->mergeWith( $existing ); 299 300 // Remove original from source 301 unset( $from[ $existing->getId() ] ); 302 } 303 304 $to->deleteHeader( Translations::HEADER_LANGUAGE ); 305 $from->deleteHeader( Translations::HEADER_LANGUAGE ); 306 PotGenerator::toFile( $to, $to_file ); 307 PotGenerator::toFile( $from, $from_file ); 308 } 256 309 }
Note: See TracChangeset
for help on using the changeset viewer.