From 79c991454b545b6f6283a6e87bdc345b76e8b237 Mon Sep 17 00:00:00 2001 From: krokodok Date: Fri, 16 Feb 2024 14:37:21 +0100 Subject: [PATCH 1/3] Make Traduttore work again with php-cli 2.10.0 --- inc/Export.php | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/inc/Export.php b/inc/Export.php index 0c2145b..26be0a1 100644 --- a/inc/Export.php +++ b/inc/Export.php @@ -81,9 +81,9 @@ public function export_strings(): ?array { // Build a mapping based on where the translation entries occur and separate the po entries. $mapping = $this->map_entries_to_source( $entries ); - $php_entries = \array_key_exists( 'php', $mapping ) ? $mapping['php'] : []; + $php_entries = \array_key_exists( 'po', $mapping ) ? $mapping['po'] : []; - unset( $mapping['php'] ); + unset( $mapping['po'] ); $this->build_json_files( $mapping ); $this->build_po_file( $php_entries ); @@ -149,25 +149,28 @@ protected function map_entries_to_source( array $entries ): array { foreach ( $entries as $entry ) { // Find all unique sources this translation originates from. - $sources = array_map( - function ( $reference ) { - $parts = explode( ':', $reference ); - $file = $parts[0]; - - if ( substr( $file, -7 ) === '.min.js' ) { - return substr( $file, 0, -7 ) . '.js'; - } - - if ( substr( $file, -3 ) === '.js' ) { - return $file; - } - - return 'php'; - }, - $entry->references - ); - - $sources = array_unique( $sources ); + if ( ! empty( $entry->references ) ) { + $sources = array_map( + function ( $reference ) { + $parts = explode( ':', $reference ); + $file = $parts[0]; + + if ( substr( $file, -7 ) === '.min.js' ) { + return substr( $file, 0, -7 ) . '.js'; + } + + if ( substr( $file, -3 ) === '.js' ) { + return $file; + } + return 'po'; + }, + $entry->references + ); + + $sources = array_unique( $sources ); + } else { + $sources = [ 'po' ]; + } foreach ( $sources as $source ) { $mapping[ $source ][] = $entry; From 675839fd988b4e357721391458e3b237455da556 Mon Sep 17 00:00:00 2001 From: krokodok Date: Fri, 16 Feb 2024 15:14:57 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Restore=20usage=20of=20=E2=80=9Aphp?= =?UTF-8?q?=E2=80=98=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/Export.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/Export.php b/inc/Export.php index 26be0a1..4768549 100644 --- a/inc/Export.php +++ b/inc/Export.php @@ -81,9 +81,9 @@ public function export_strings(): ?array { // Build a mapping based on where the translation entries occur and separate the po entries. $mapping = $this->map_entries_to_source( $entries ); - $php_entries = \array_key_exists( 'po', $mapping ) ? $mapping['po'] : []; + $php_entries = \array_key_exists( 'php', $mapping ) ? $mapping['php'] : []; - unset( $mapping['po'] ); + unset( $mapping['php'] ); $this->build_json_files( $mapping ); $this->build_po_file( $php_entries ); @@ -162,14 +162,14 @@ function ( $reference ) { if ( substr( $file, -3 ) === '.js' ) { return $file; } - return 'po'; + return 'php'; }, $entry->references ); $sources = array_unique( $sources ); } else { - $sources = [ 'po' ]; + $sources = [ 'php' ]; } foreach ( $sources as $source ) { From 119f9e661888ee683ff7bce1f4851f1e95534407 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Fri, 16 Feb 2024 15:30:44 +0100 Subject: [PATCH 3/3] restore empty line --- inc/Export.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/Export.php b/inc/Export.php index 4768549..4ba5da8 100644 --- a/inc/Export.php +++ b/inc/Export.php @@ -162,6 +162,7 @@ function ( $reference ) { if ( substr( $file, -3 ) === '.js' ) { return $file; } + return 'php'; }, $entry->references