WordPress.org

Making WordPress.org

Opened 5 weeks ago

Closed 3 weeks ago

#5314 closed task (fixed)

Update string extraction and export for WordPress core to keep originals for JavaScript files in their original project

Reported by: ocean90 Owned by: ocean90
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)

#1 @ocean90
5 weeks 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
5 weeks 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
3 weeks 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.