[wp-meta] [Making WordPress.org] #5314: Update string extraction and export for WordPress core to keep originals for JavaScript files in their original project

Making WordPress.org noreply at wordpress.org
Fri Jul 10 13:05:44 UTC 2020


#5314: Update string extraction and export for WordPress core to keep originals
for JavaScript files in their original project
--------------------------------------+----------------------
 Reporter:  ocean90                   |      Owner:  ocean90
     Type:  task                      |     Status:  assigned
 Priority:  high                      |  Milestone:
Component:  Translate Site & Plugins  |   Keywords:
--------------------------------------+----------------------
 Example: The string "Done" exists in `wp-includes/customize/class-wp-
 customize-nav-menu-control.php:57` and `wp-includes/customize/class-wp-
 widget-area-customize-control.php:61` but also in `wp-
 admin/includes/widgets.php:298` and `wp-admin/js/set-post-
 thumbnail.js:21`. The current merge behaviour removes the last two from
 the admin project thus no JSON translation can be created for `set-post-
 thumbnail.js`.

 This affects the custom
 [https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html
 /wp-content/plugins/wporg-gp-customizations/inc/cli/class-make-core-
 pot.php make-pot command] and the
 [https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html
 /wp-content/plugins/wporg-gp-customizations/inc/cli/class-export.php
 export command]. Instead of using WP-CLI's default `--subtract` argument
 for make-pot we need a custom merge task and/or the export command needs
 to be able to merge existing JSON files.


 {{{#!php
 <?php
 $wordpress_originals = new Translations();
 Po::fromFile( $this->destination . '/wordpress.pot', $wordpress_originals
 );
 $wordpress_admin_originals = new Translations();
 Po::fromFile( $this->destination . '/wordpress-admin.pot',
 $wordpress_admin_originals );

 foreach ( $wordpress_originals as $id => $wordpress_original ) {
         $existing = $wordpress_admin_originals->find( $wordpress_original
 );
         if ( ! $existing ) {
                 continue;
         }

         // Merge.
         $wordpress_original->mergeWith( $existing );

         // Remove original from source, but only if it didn't include a
 reference to a JavaScript file.
         $can_delete = true;
         $references = $existing->getReferences();
         if ( $references ) {
                 foreach ( $references as $reference ) {
                         if ( '.js' === substr( $reference[0], -3 ) ) {
                                 $can_delete = false;
                                 break;
                         }
                 }
         }

         if ( $can_delete ) {
                 unset( $wordpress_admin_originals[ $existing->getId() ] );
         }
 }

 PotGenerator::toFile( $wordpress_originals, $this->destination .
 '/wordpress.pot' );
 PotGenerator::toFile( $wordpress_admin_originals, $this->destination .
 '/wordpress-admin.pot' );
 }}}



 Related: #WP20881, https://github.com/wp-cli/i18n-command/issues/105

-- 
Ticket URL: <https://meta.trac.wordpress.org/ticket/5314>
Making WordPress.org <https://meta.trac.wordpress.org/>
Making WordPress.org


More information about the wp-meta mailing list