From 79c991454b545b6f6283a6e87bdc345b76e8b237 Mon Sep 17 00:00:00 2001 From: krokodok Date: Fri, 16 Feb 2024 14:37:21 +0100 Subject: [PATCH] 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;