diff --git a/inc/Export.php b/inc/Export.php index 0c2145b..4ba5da8 100644 --- a/inc/Export.php +++ b/inc/Export.php @@ -149,25 +149,29 @@ 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 'php'; + }, + $entry->references + ); + + $sources = array_unique( $sources ); + } else { + $sources = [ 'php' ]; + } foreach ( $sources as $source ) { $mapping[ $source ][] = $entry;