From d0ee62ca2a56e290fb62b77195bb1f52393c41f3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Feb 2026 09:42:29 +0000 Subject: [PATCH 1/8] Initial plan From 04efaf233e8da2c9c353bcefc617071412d9e0c1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Feb 2026 09:46:30 +0000 Subject: [PATCH 2/8] Remove purge and update-mo-files flags from make-json, add JS filtering to make-mo and make-php Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/MakeJsonCommand.php | 74 ++++------------------------------------- src/MakeMoCommand.php | 35 +++++++++++++++++++ src/MakePhpCommand.php | 37 ++++++++++++++++++++- 3 files changed, 77 insertions(+), 69 deletions(-) diff --git a/src/MakeJsonCommand.php b/src/MakeJsonCommand.php index 2076ac57..b52c9a29 100644 --- a/src/MakeJsonCommand.php +++ b/src/MakeJsonCommand.php @@ -3,7 +3,6 @@ namespace WP_CLI\I18n; use Gettext\Extractors\Po as PoExtractor; -use Gettext\Generators\Po as PoGenerator; use Gettext\Translation; use Gettext\Translations; use WP_CLI; @@ -44,13 +43,6 @@ class MakeJsonCommand extends WP_CLI_Command { * [--extensions=] * : Additional custom JS extensions, comma separated list. By default searches for .min.js and .js extensions. * - * [--purge] - * : Whether to purge the strings that were extracted from the original source file. Defaults to true, use `--no-purge` to skip the removal. - * - * [--update-mo-files] - * : Whether MO files should be updated as well after updating PO files. - * Only has an effect when used in combination with `--purge`. - * * [--pretty-print] * : Pretty-print resulting JSON files. * @@ -63,8 +55,8 @@ class MakeJsonCommand extends WP_CLI_Command { * # Create JSON files for all PO files in the languages directory * $ wp i18n make-json languages * - * # Create JSON files for my-plugin-de_DE.po and leave the PO file untouched. - * $ wp i18n make-json my-plugin-de_DE.po /tmp --no-purge + * # Create JSON files for my-plugin-de_DE.po + * $ wp i18n make-json my-plugin-de_DE.po /tmp * * # Create JSON files with mapping * $ wp i18n make-json languages --use-map=build/map.json @@ -80,12 +72,10 @@ class MakeJsonCommand extends WP_CLI_Command { * @throws WP_CLI\ExitException */ public function __invoke( $args, $assoc_args ) { - $assoc_args = Utils\parse_shell_arrays( $assoc_args, array( 'use-map' ) ); - $purge = Utils\get_flag_value( $assoc_args, 'purge', true ); - $update_mo_files = Utils\get_flag_value( $assoc_args, 'update-mo-files', true ); - $map_paths = Utils\get_flag_value( $assoc_args, 'use-map', false ); - $domain = Utils\get_flag_value( $assoc_args, 'domain', '' ); - $extensions = array_map( + $assoc_args = Utils\parse_shell_arrays( $assoc_args, array( 'use-map' ) ); + $map_paths = Utils\get_flag_value( $assoc_args, 'use-map', false ); + $domain = Utils\get_flag_value( $assoc_args, 'domain', '' ); + $extensions = array_map( function ( $extension ) { return trim( $extension, ' .' ); }, @@ -130,25 +120,6 @@ function ( $extension ) { if ( $file->isFile() && $file->isReadable() && 'po' === $file->getExtension() ) { $result = $this->make_json( $file->getRealPath(), $destination, $map, $domain, $extensions ); $result_count += count( $result ); - - if ( $purge ) { - $removed = $this->remove_js_strings_from_po_file( $file->getRealPath() ); - - if ( ! $removed ) { - WP_CLI::warning( sprintf( 'Could not update file %s', basename( $source ) ) ); - continue; - } - - if ( $update_mo_files ) { - $file_basename = basename( $file->getFilename(), '.po' ); - $destination_file = "{$destination}/{$file_basename}.mo"; - - $translations = Translations::fromPoFile( $file->getPathname() ); - if ( ! $translations->toMoFile( $destination_file ) ) { - WP_CLI::warning( "Could not create file {$destination_file}" ); - } - } - } } } @@ -385,37 +356,4 @@ protected function build_json_files( $mapping, $base_file_name, $destination ) { return $result; } - - /** - * Removes strings from PO file that only occur in JavaScript file. - * - * @param string $source_file Path to the PO file. - * @return bool True on success, false otherwise. - */ - protected function remove_js_strings_from_po_file( $source_file ) { - /** @var Translations[] $mapping */ - $translations = new Translations(); - - PoExtractor::fromFile( $source_file, $translations ); - - foreach ( $translations->getArrayCopy() as $translation ) { - /** @var Translation $translation */ - - if ( ! $translation->hasReferences() ) { - continue; - } - - foreach ( $translation->getReferences() as $reference ) { - $file = $reference[0]; - - if ( substr( $file, - 3 ) !== '.js' ) { - continue 2; - } - } - - unset( $translations[ $translation->getId() ] ); - } - - return PoGenerator::toFile( $translations, $source_file ); - } } diff --git a/src/MakeMoCommand.php b/src/MakeMoCommand.php index a13eeabc..fb599f14 100644 --- a/src/MakeMoCommand.php +++ b/src/MakeMoCommand.php @@ -3,6 +3,7 @@ namespace WP_CLI\I18n; use DirectoryIterator; +use Gettext\Translation; use Gettext\Translations; use IteratorIterator; use SplFileInfo; @@ -88,6 +89,10 @@ public function __invoke( $args, $assoc_args ) { $destination_file = "{$destination}/{$file_name}"; $translations = Translations::fromPoFile( $file->getPathname() ); + + // Remove JS-only strings from MO files to keep them small. + $this->remove_js_only_strings( $translations ); + if ( ! $translations->toMoFile( $destination_file ) ) { WP_CLI::warning( sprintf( 'Could not create file %s', $destination_file ) ); continue; @@ -98,4 +103,34 @@ public function __invoke( $args, $assoc_args ) { WP_CLI::success( sprintf( 'Created %d %s.', $result_count, Utils\pluralize( 'file', $result_count ) ) ); } + + /** + * Removes strings from translations that only occur in JavaScript files. + * + * @param Translations $translations The translations instance to filter. + */ + protected function remove_js_only_strings( $translations ) { + foreach ( $translations->getArrayCopy() as $translation ) { + /** @var Translation $translation */ + + if ( ! $translation->hasReferences() ) { + continue; + } + + $has_non_js_reference = false; + foreach ( $translation->getReferences() as $reference ) { + $file = $reference[0]; + + if ( substr( $file, -3 ) !== '.js' ) { + $has_non_js_reference = true; + break; + } + } + + // If all references are JS files, remove this translation. + if ( ! $has_non_js_reference ) { + unset( $translations[ $translation->getId() ] ); + } + } + } } diff --git a/src/MakePhpCommand.php b/src/MakePhpCommand.php index 1e7622e8..9e303abc 100644 --- a/src/MakePhpCommand.php +++ b/src/MakePhpCommand.php @@ -3,6 +3,7 @@ namespace WP_CLI\I18n; use DirectoryIterator; +use Gettext\Translation; use Gettext\Translations; use IteratorIterator; use SplFileInfo; @@ -82,7 +83,11 @@ public function __invoke( $args, $assoc_args ) { $destination_file = "{$destination}/{$file_basename}.l10n.php"; $translations = Translations::fromPoFile( $file->getPathname() ); - $options = [ 'prettyPrint' => $pretty_print ]; + + // Remove JS-only strings from PHP files to keep them small. + $this->remove_js_only_strings( $translations ); + + $options = [ 'prettyPrint' => $pretty_print ]; if ( ! PhpArrayGenerator::toFile( $translations, $destination_file, $options ) ) { WP_CLI::warning( sprintf( 'Could not create file %s', $destination_file ) ); continue; @@ -93,4 +98,34 @@ public function __invoke( $args, $assoc_args ) { WP_CLI::success( sprintf( 'Created %d %s.', $result_count, Utils\pluralize( 'file', $result_count ) ) ); } + + /** + * Removes strings from translations that only occur in JavaScript files. + * + * @param Translations $translations The translations instance to filter. + */ + protected function remove_js_only_strings( $translations ) { + foreach ( $translations->getArrayCopy() as $translation ) { + /** @var Translation $translation */ + + if ( ! $translation->hasReferences() ) { + continue; + } + + $has_non_js_reference = false; + foreach ( $translation->getReferences() as $reference ) { + $file = $reference[0]; + + if ( substr( $file, -3 ) !== '.js' ) { + $has_non_js_reference = true; + break; + } + } + + // If all references are JS files, remove this translation. + if ( ! $has_non_js_reference ) { + unset( $translations[ $translation->getId() ] ); + } + } + } } From 09712d0800bb0f31fec0bf3df9b30d1a4f988635 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Feb 2026 09:47:50 +0000 Subject: [PATCH 3/8] Update tests to reflect new behavior: PO files untouched, JS filtering in make-mo/make-php Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/makejson.feature | 106 ++------------------------------------ features/makemo.feature | 56 ++++++++++++++++++++ features/makephp.feature | 56 ++++++++++++++++++++ 3 files changed, 116 insertions(+), 102 deletions(-) diff --git a/features/makejson.feature b/features/makejson.feature index dc8ab19f..f5314ef5 100644 --- a/features/makejson.feature +++ b/features/makejson.feature @@ -325,15 +325,15 @@ Feature: Split PO files into JSON files. """ "D" """ - And the foo-plugin/foo-plugin-de_DE.po file should not contain: + And the foo-plugin/foo-plugin-de_DE.po file should contain: """ "A" """ - And the foo-plugin/foo-plugin-de_DE.po file should not contain: + And the foo-plugin/foo-plugin-de_DE.po file should contain: """ "B" """ - And the foo-plugin/foo-plugin-de_DE.po file should not contain: + And the foo-plugin/foo-plugin-de_DE.po file should contain: """ "C" """ @@ -377,7 +377,7 @@ Feature: Split PO files into JSON files. msgstr "D" """ - When I run `wp i18n make-json foo-plugin --no-purge` + When I run `wp i18n make-json foo-plugin` Then STDOUT should contain: """ Success: Created 2 files. @@ -437,104 +437,6 @@ Feature: Split PO files into JSON files. "C" """ - Scenario: Does generate or update MO files - Given an empty foo-plugin directory - And a foo-plugin/foo-plugin-de_DE.po file: - """ - # Copyright (C) 2018 Foo Plugin - # This file is distributed under the same license as the Foo Plugin package. - msgid "" - msgstr "" - "Project-Id-Version: Foo Plugin\n" - "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n" - "Last-Translator: FULL NAME \n" - "Language-Team: LANGUAGE \n" - "Language: de_DE\n" - "MIME-Version: 1.0\n" - "Content-Type: text/plain; charset=UTF-8\n" - "Content-Transfer-Encoding: 8bit\n" - "POT-Creation-Date: 2018-05-02T22:06:24+00:00\n" - "PO-Revision-Date: 2018-05-02T22:06:24+00:00\n" - "X-Domain: foo-plugin\n" - "Plural-Forms: nplurals=2; plural=(n != 1);\n" - - #: a.js:10 - msgid "A" - msgstr "A" - - #: b.js:10 - msgid "B" - msgstr "B" - - #: a.js:10 - #: b.js:10 - msgid "C" - msgstr "C" - - #: foo-plugin.php:10 - msgid "D" - msgstr "D" - """ - - When I run `wp i18n make-json foo-plugin` - Then STDOUT should contain: - """ - Success: Created 2 files. - """ - And the return code should be 0 - - And the foo-plugin/foo-plugin-de_DE-95f0a310f289230d56c3a4949c17963e.json file should exist - And the foo-plugin/foo-plugin-de_DE.mo file should exist - - Scenario: Does not generate or update MO files - Given an empty foo-plugin directory - And a foo-plugin/foo-plugin-de_DE.po file: - """ - # Copyright (C) 2018 Foo Plugin - # This file is distributed under the same license as the Foo Plugin package. - msgid "" - msgstr "" - "Project-Id-Version: Foo Plugin\n" - "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n" - "Last-Translator: FULL NAME \n" - "Language-Team: LANGUAGE \n" - "Language: de_DE\n" - "MIME-Version: 1.0\n" - "Content-Type: text/plain; charset=UTF-8\n" - "Content-Transfer-Encoding: 8bit\n" - "POT-Creation-Date: 2018-05-02T22:06:24+00:00\n" - "PO-Revision-Date: 2018-05-02T22:06:24+00:00\n" - "X-Domain: foo-plugin\n" - "Plural-Forms: nplurals=2; plural=(n != 1);\n" - - #: a.js:10 - msgid "A" - msgstr "A" - - #: b.js:10 - msgid "B" - msgstr "B" - - #: a.js:10 - #: b.js:10 - msgid "C" - msgstr "C" - - #: foo-plugin.php:10 - msgid "D" - msgstr "D" - """ - - When I run `wp i18n make-json foo-plugin --no-update-mo-files` - Then STDOUT should contain: - """ - Success: Created 2 files. - """ - And the return code should be 0 - - And the foo-plugin/foo-plugin-de_DE-95f0a310f289230d56c3a4949c17963e.json file should exist - And the foo-plugin/foo-plugin-de_DE.mo file should not exist - Scenario: Correctly saves strings with context Given an empty foo-plugin directory And a foo-plugin/foo-plugin-de_DE.po file: diff --git a/features/makemo.feature b/features/makemo.feature index c1bff75d..8b86d62e 100644 --- a/features/makemo.feature +++ b/features/makemo.feature @@ -198,3 +198,59 @@ Feature: Generate MO files from PO files """ Bar Plugin """ + + Scenario: Excludes JS-only strings from MO files + Given an empty foo-plugin directory + And a foo-plugin/foo-plugin-de_DE.po file: + """ + # Copyright (C) 2018 Foo Plugin + # This file is distributed under the same license as the Foo Plugin package. + msgid "" + msgstr "" + "Project-Id-Version: Foo Plugin\n" + "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n" + "Last-Translator: FULL NAME \n" + "Language-Team: LANGUAGE \n" + "Language: de_DE\n" + "MIME-Version: 1.0\n" + "Content-Type: text/plain; charset=UTF-8\n" + "Content-Transfer-Encoding: 8bit\n" + "POT-Creation-Date: 2018-05-02T22:06:24+00:00\n" + "PO-Revision-Date: 2018-05-02T22:06:24+00:00\n" + "X-Domain: foo-plugin\n" + "Plural-Forms: nplurals=2; plural=(n != 1);\n" + + #: foo-plugin.js:15 + msgid "JS Only String" + msgstr "JS Only Translation" + + #: foo-plugin.php:10 + msgid "PHP String" + msgstr "PHP Translation" + + #: foo-plugin.js:20 + #: foo-plugin.php:15 + msgid "Both JS and PHP" + msgstr "Both Translation" + """ + + When I run `wp i18n make-mo foo-plugin` + Then STDOUT should contain: + """ + Success: Created 1 file. + """ + And the return code should be 0 + And the foo-plugin/foo-plugin-de_DE.mo file should exist + And the foo-plugin/foo-plugin-de_DE.mo file should contain: + """ + PHP Translation + """ + And the foo-plugin/foo-plugin-de_DE.mo file should contain: + """ + Both Translation + """ + And the foo-plugin/foo-plugin-de_DE.mo file should not contain: + """ + JS Only Translation + """ + diff --git a/features/makephp.feature b/features/makephp.feature index d345dea4..b642fe03 100644 --- a/features/makephp.feature +++ b/features/makephp.feature @@ -300,3 +300,59 @@ Feature: Generate PHP files from PO files """ 'messages' => [ """ + + Scenario: Excludes JS-only strings from PHP files + Given an empty foo-plugin directory + And a foo-plugin/foo-plugin-de_DE.po file: + """ + # Copyright (C) 2018 Foo Plugin + # This file is distributed under the same license as the Foo Plugin package. + msgid "" + msgstr "" + "Project-Id-Version: Foo Plugin\n" + "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n" + "Last-Translator: FULL NAME \n" + "Language-Team: LANGUAGE \n" + "Language: de_DE\n" + "MIME-Version: 1.0\n" + "Content-Type: text/plain; charset=UTF-8\n" + "Content-Transfer-Encoding: 8bit\n" + "POT-Creation-Date: 2018-05-02T22:06:24+00:00\n" + "PO-Revision-Date: 2018-05-02T22:06:24+00:00\n" + "X-Domain: foo-plugin\n" + "Plural-Forms: nplurals=2; plural=(n != 1);\n" + + #: foo-plugin.js:15 + msgid "JS Only String" + msgstr "JS Only Translation" + + #: foo-plugin.php:10 + msgid "PHP String" + msgstr "PHP Translation" + + #: foo-plugin.js:20 + #: foo-plugin.php:15 + msgid "Both JS and PHP" + msgstr "Both Translation" + """ + + When I run `wp i18n make-php foo-plugin` + Then STDOUT should contain: + """ + Success: Created 1 file. + """ + And the return code should be 0 + And the foo-plugin/foo-plugin-de_DE.l10n.php file should exist + And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain: + """ + PHP Translation + """ + And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain: + """ + Both Translation + """ + And the foo-plugin/foo-plugin-de_DE.l10n.php file should not contain: + """ + JS Only Translation + """ + From afd57cbb1363a4af37d4cc042d04f8302aa14a78 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Feb 2026 09:49:29 +0000 Subject: [PATCH 4/8] Fix tests for make-mo and make-php to account for JS-only string filtering Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/makemo.feature | 2 +- features/makephp.feature | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/features/makemo.feature b/features/makemo.feature index 8b86d62e..ae0e2585 100644 --- a/features/makemo.feature +++ b/features/makemo.feature @@ -183,7 +183,7 @@ Feature: Generate MO files from PO files "X-Domain: foo-plugin\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" - #: foo-plugin.js:15 + #: foo-plugin.php:15 msgid "Foo Plugin" msgstr "Bar Plugin" """ diff --git a/features/makephp.feature b/features/makephp.feature index b642fe03..66f12711 100644 --- a/features/makephp.feature +++ b/features/makephp.feature @@ -202,7 +202,15 @@ Feature: Generate PHP files from PO files And the return code should be 0 And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain: """ - return ['domain'=>'foo-plugin','plural-forms'=>'nplurals=2; plural=(n != 1);','language'=>'de_DE','project-id-version'=>'Foo Plugin','pot-creation-date'=>'2018-05-02T22:06:24+00:00','po-revision-date'=>'2018-05-02T22:06:24+00:00','messages'=>['Plugin NameFoo Plugin (EN)'=>'Foo Plugin (DE)','Foo Plugin'=>'Bar Plugin','You have %d new message'=>'Sie haben %d neue Nachricht' . "\0" . 'Sie haben %d neue Nachrichten']]; + You have %d new message + """ + And the foo-plugin/foo-plugin-de_DE.l10n.php file should not contain: + """ + Foo Plugin (DE) + """ + And the foo-plugin/foo-plugin-de_DE.l10n.php file should not contain: + """ + Bar Plugin """ Scenario: Excludes strings without translations From 6a0a823aa621031b74cffe4e5a4d098e6617c2c4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Feb 2026 09:53:10 +0000 Subject: [PATCH 5/8] Extract JS filtering logic to trait and support more JS file extensions Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/JsStringFilterTrait.php | 46 +++++++++++++++++++++++++++++++++++++ src/MakeMoCommand.php | 32 ++------------------------ src/MakePhpCommand.php | 32 ++------------------------ 3 files changed, 50 insertions(+), 60 deletions(-) create mode 100644 src/JsStringFilterTrait.php diff --git a/src/JsStringFilterTrait.php b/src/JsStringFilterTrait.php new file mode 100644 index 00000000..c3539286 --- /dev/null +++ b/src/JsStringFilterTrait.php @@ -0,0 +1,46 @@ +getArrayCopy() as $translation ) { + /** @var Translation $translation */ + + if ( ! $translation->hasReferences() ) { + continue; + } + + $has_non_js_reference = false; + foreach ( $translation->getReferences() as $reference ) { + $file = $reference[0]; + $extension = '.' . pathinfo( $file, PATHINFO_EXTENSION ); + + if ( ! in_array( $extension, self::$js_extensions, true ) ) { + $has_non_js_reference = true; + break; + } + } + + // If all references are JS files, remove this translation. + if ( ! $has_non_js_reference ) { + unset( $translations[ $translation->getId() ] ); + } + } + } +} diff --git a/src/MakeMoCommand.php b/src/MakeMoCommand.php index fb599f14..89bc9865 100644 --- a/src/MakeMoCommand.php +++ b/src/MakeMoCommand.php @@ -12,6 +12,8 @@ use WP_CLI_Command; class MakeMoCommand extends WP_CLI_Command { + use JsStringFilterTrait; + /** * Create MO files from PO files. * @@ -103,34 +105,4 @@ public function __invoke( $args, $assoc_args ) { WP_CLI::success( sprintf( 'Created %d %s.', $result_count, Utils\pluralize( 'file', $result_count ) ) ); } - - /** - * Removes strings from translations that only occur in JavaScript files. - * - * @param Translations $translations The translations instance to filter. - */ - protected function remove_js_only_strings( $translations ) { - foreach ( $translations->getArrayCopy() as $translation ) { - /** @var Translation $translation */ - - if ( ! $translation->hasReferences() ) { - continue; - } - - $has_non_js_reference = false; - foreach ( $translation->getReferences() as $reference ) { - $file = $reference[0]; - - if ( substr( $file, -3 ) !== '.js' ) { - $has_non_js_reference = true; - break; - } - } - - // If all references are JS files, remove this translation. - if ( ! $has_non_js_reference ) { - unset( $translations[ $translation->getId() ] ); - } - } - } } diff --git a/src/MakePhpCommand.php b/src/MakePhpCommand.php index 9e303abc..adecee2c 100644 --- a/src/MakePhpCommand.php +++ b/src/MakePhpCommand.php @@ -12,6 +12,8 @@ use WP_CLI_Command; class MakePhpCommand extends WP_CLI_Command { + use JsStringFilterTrait; + /** * Create PHP files from PO files. * @@ -98,34 +100,4 @@ public function __invoke( $args, $assoc_args ) { WP_CLI::success( sprintf( 'Created %d %s.', $result_count, Utils\pluralize( 'file', $result_count ) ) ); } - - /** - * Removes strings from translations that only occur in JavaScript files. - * - * @param Translations $translations The translations instance to filter. - */ - protected function remove_js_only_strings( $translations ) { - foreach ( $translations->getArrayCopy() as $translation ) { - /** @var Translation $translation */ - - if ( ! $translation->hasReferences() ) { - continue; - } - - $has_non_js_reference = false; - foreach ( $translation->getReferences() as $reference ) { - $file = $reference[0]; - - if ( substr( $file, -3 ) !== '.js' ) { - $has_non_js_reference = true; - break; - } - } - - // If all references are JS files, remove this translation. - if ( ! $has_non_js_reference ) { - unset( $translations[ $translation->getId() ] ); - } - } - } } From 84c613f86f9b48480c06f06157fb0dbc96779321 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 9 Feb 2026 18:24:37 +0100 Subject: [PATCH 6/8] Update src/JsStringFilterTrait.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/JsStringFilterTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsStringFilterTrait.php b/src/JsStringFilterTrait.php index c3539286..7f4ef658 100644 --- a/src/JsStringFilterTrait.php +++ b/src/JsStringFilterTrait.php @@ -18,7 +18,7 @@ trait JsStringFilterTrait { * * @param Translations $translations The translations instance to filter. */ - protected function remove_js_only_strings( $translations ) { + protected function remove_js_only_strings( Translations $translations ): void { foreach ( $translations->getArrayCopy() as $translation ) { /** @var Translation $translation */ From 6582da5c4017277ea6b3d44b7f3bdadc1088fff1 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 9 Feb 2026 18:24:47 +0100 Subject: [PATCH 7/8] Update src/JsStringFilterTrait.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/JsStringFilterTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsStringFilterTrait.php b/src/JsStringFilterTrait.php index 7f4ef658..46b03759 100644 --- a/src/JsStringFilterTrait.php +++ b/src/JsStringFilterTrait.php @@ -29,7 +29,7 @@ protected function remove_js_only_strings( Translations $translations ): void { $has_non_js_reference = false; foreach ( $translation->getReferences() as $reference ) { $file = $reference[0]; - $extension = '.' . pathinfo( $file, PATHINFO_EXTENSION ); + $extension = '.' . strtolower( pathinfo( $file, PATHINFO_EXTENSION ) ); if ( ! in_array( $extension, self::$js_extensions, true ) ) { $has_non_js_reference = true; From 8c8e46c8a906aed6b05989fd55dc109b4b20028e Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 9 Feb 2026 18:25:58 +0100 Subject: [PATCH 8/8] Apply suggestion from @swissspidy --- src/JsStringFilterTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsStringFilterTrait.php b/src/JsStringFilterTrait.php index 46b03759..c1ace362 100644 --- a/src/JsStringFilterTrait.php +++ b/src/JsStringFilterTrait.php @@ -31,7 +31,7 @@ protected function remove_js_only_strings( Translations $translations ): void { $file = $reference[0]; $extension = '.' . strtolower( pathinfo( $file, PATHINFO_EXTENSION ) ); - if ( ! in_array( $extension, self::$js_extensions, true ) ) { + if ( ! in_array( $extension, static::$js_extensions, true ) ) { $has_non_js_reference = true; break; }