Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export translation entries without references to files #265

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions inc/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
ocean90 marked this conversation as resolved.
Show resolved Hide resolved
},
$entry->references
);

$sources = array_unique( $sources );
} else {
$sources = [ 'php' ];
}

foreach ( $sources as $source ) {
$mapping[ $source ][] = $entry;
Expand Down
Loading