Opened 4 years ago

Closed 4 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: ocean90's profile ocean90 Owned by: ocean90's profile ocean90
Milestone: Priority: high
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 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.

$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 ) {

        // 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;

        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,

Change History (3)

#1 @ocean90
4 years ago

In 10063:

Translate: Adjust make-core-pot command to merge references and comments of duplicate originals before removing the duplicates.

Also, fix duplicate file comments in POT files and improve exclude lists.

See #5314.

#2 @ocean90
4 years ago

In 10064:

Translate: When exporting the JSON files for WordPress core JavaScript translations, check for an existing JSON file and merge translations accordingly.

See #5314.

#3 @ocean90
4 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 10097:

Translate: Don't export all entries to PO files.

This workaround is no longer necessary as of [10063].

Fixes #5314.

Note: See TracTickets for help on using tickets.