Skip to content

Commit

Permalink
Make Traduttore work again with php-cli 2.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
krokodok committed Feb 16, 2024
1 parent a9faec1 commit 79c9914
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions inc/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 79c9914

Please sign in to comment.