diff --git a/src/wp-includes/class.wp-scripts.php b/src/wp-includes/class.wp-scripts.php
index aebf3a3b59..246d1fe6a2 100644
--- a/src/wp-includes/class.wp-scripts.php
+++ b/src/wp-includes/class.wp-scripts.php
@@ -311,6 +311,8 @@ class WP_Scripts extends WP_Dependencies {
$inline_script_tag = '';
}
+ $translations_stop_concat = ! empty( $obj->textdomain );
+
$translations = $this->print_translations( $handle, false );
if ( $translations ) {
$translations = sprintf( "\n", $this->type_attr, esc_attr( $handle ), $translations );
@@ -327,7 +329,7 @@ class WP_Scripts extends WP_Dependencies {
*/
$srce = apply_filters( 'script_loader_src', $src, $handle );
- if ( $this->in_default_dir( $srce ) && ( $before_handle || $after_handle || $translations ) ) {
+ if ( $this->in_default_dir( $srce ) && ( $before_handle || $after_handle || $translations_stop_concat ) ) {
$this->do_concat = false;
// Have to print the so-far concatenated scripts right away to maintain the right order.
diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php
index a31628e26b..e799247352 100644
--- a/tests/phpunit/tests/dependencies/scripts.php
+++ b/tests/phpunit/tests/dependencies/scripts.php
@@ -1481,4 +1481,38 @@ JS;
array( false, '[""]' ),
);
}
+
+ /**
+ * @ticket 55628
+ * @covers ::wp_set_script_translations
+ */
+ public function test_wp_external_wp_i18n_print_order() {
+ global $wp_scripts;
+
+ $wp_scripts->do_concat = true;
+ $wp_scripts->default_dirs = array( '/default/' );
+
+ // wp-i18n script in a non-default directory.
+ wp_register_script( 'wp-i18n', '/plugins/wp-i18n.js', array(), null );
+ // Script in default dir that's going to be concatenated.
+ wp_enqueue_script( 'jquery-core', '/default/jquery-core.js', array(), null );
+ // Script in default dir that depends on wp-i18n.
+ wp_enqueue_script( 'common', '/default/common.js', array(), null );
+ wp_set_script_translations( 'common' );
+
+ $print_scripts = get_echo(
+ function() {
+ wp_print_scripts();
+ _print_scripts();
+ }
+ );
+
+ // The non-default script should end concatenation and maintain order.
+ $ver = get_bloginfo( 'version' );
+ $expected = "\n";
+ $expected .= "\n";
+ $expected .= "\n";
+
+ $this->assertSame( $expected, $print_scripts );
+ }
}