Opened 5 years ago
Closed 5 years ago
#5314 closed task (blessed) (fixed)
Update string extraction and export for WordPress core to keep originals for JavaScript files in their original project
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | high | |
Component: | Translate Site & Plugins | Keywords: | |
Cc: |
Description
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 make-pot command and the 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 $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
Change History (3)
Note: See
TracTickets for help on using
tickets.
In 10063: