Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Cleanup and updates based on feedback
  • Loading branch information
michaelw85 committed Apr 25, 2025
commit 952f493d72c87921144e30025b73d9806829e5fa
6 changes: 3 additions & 3 deletions features/makejson.feature
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ Feature: Split PO files into JSON files.
And the return code should be 0
And the foo-theme/my-custom-domain-de_DE-557240f2080a0894dbd39f5c2f559bf8.json file should exist

Scenario: Should only proces js/min.js extensions by default
Scenario: Should only process js/min.js extensions by default
Given an empty foo-theme directory
And a foo-theme/de_DE.po file:
"""
Expand All @@ -1010,7 +1010,7 @@ Feature: Split PO files into JSON files.
msgid "Foo Theme"
msgstr "Foo Theme"

#: bar-minified.min.js:15
#: bar.min.minified.min.js:15
msgid "Foo Theme"
msgstr "Foo Theme"

Expand All @@ -1030,7 +1030,7 @@ Feature: Split PO files into JSON files.
"""
And the return code should be 0
And the foo-theme/foo-theme-de_DE-557240f2080a0894dbd39f5c2f559bf8.json file should exist
And the foo-theme/foo-theme-de_DE-da8cc4943ac0f9e5cc173c7de3f7299d.json file should exist
And the foo-theme/foo-theme-de_DE-a9c6627f5fe96185c0a0d0ddd8fa0216.json file should exist

Scenario: Allows processing custom file extensions
Given an empty foo-theme directory
Expand Down
Binary file removed foo/empty.mo
Binary file not shown.
Binary file removed foo/translations.mo
Binary file not shown.
7 changes: 4 additions & 3 deletions src/MakeJsonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@
$update_mo_files = Utils\get_flag_value( $assoc_args, 'update-mo-files', true );
$map_paths = Utils\get_flag_value( $assoc_args, 'use-map', false );
$domain = Utils\get_flag_value( $assoc_args, 'domain', '' );
$extensions = array_map(
function ( $extension ) {
return trim( $extension, ' .' );
},
explode( ',', Utils\get_flag_value( $assoc_args, 'extensions', '' ) )
);

Check warning on line 93 in src/MakeJsonCommand.php

View check run for this annotation

Codecov / codecov/patch

src/MakeJsonCommand.php#L88-L93

Added lines #L88 - L93 were not covered by tests

if ( Utils\get_flag_value( $assoc_args, 'pretty-print', false ) ) {
$this->json_options |= JSON_PRETTY_PRINT;
Expand Down Expand Up @@ -128,7 +128,7 @@
/** @var DirectoryIterator $file */
foreach ( $files as $file ) {
if ( $file->isFile() && $file->isReadable() && 'po' === $file->getExtension() ) {
$result = $this->make_json( $file->getRealPath(), $destination, $map, $domain, $extensions );

Check warning on line 131 in src/MakeJsonCommand.php

View check run for this annotation

Codecov / codecov/patch

src/MakeJsonCommand.php#L131

Added line #L131 was not covered by tests
$result_count += count( $result );

if ( $purge ) {
Expand Down Expand Up @@ -240,12 +240,12 @@
* @param array $extensions Additional extensions.
* @return array List of created JSON files.
*/
protected function make_json( $source_file, $destination, $map, $domain, $extensions ) {

Check warning on line 243 in src/MakeJsonCommand.php

View check run for this annotation

Codecov / codecov/patch

src/MakeJsonCommand.php#L243

Added line #L243 was not covered by tests
/** @var Translations[] $mapping */
$mapping = [];
$translations = new Translations();
$result = [];
$extensions = array_merge( [ 'js' ], $extensions );

Check warning on line 248 in src/MakeJsonCommand.php

View check run for this annotation

Codecov / codecov/patch

src/MakeJsonCommand.php#L248

Added line #L248 was not covered by tests

PoExtractor::fromFile( $source_file, $translations );

Expand All @@ -262,12 +262,13 @@

// Find all unique sources this translation originates from.
$sources = array_map(
static function ( $reference ) use ( $extensions ) {
$file = $reference[0];

$file = $reference[0];
$extension = pathinfo( $file, PATHINFO_EXTENSION );

Check warning on line 267 in src/MakeJsonCommand.php

View check run for this annotation

Codecov / codecov/patch

src/MakeJsonCommand.php#L265-L267

Added lines #L265 - L267 were not covered by tests

return in_array( $extension, $extensions, true ) ? str_replace( '.min.', '.', $file ) : null;
return in_array( $extension, $extensions, true )
? preg_replace( "/.min.{$extension}$/", ".{$extension}", $file )
: null;

Check warning on line 271 in src/MakeJsonCommand.php

View check run for this annotation

Codecov / codecov/patch

src/MakeJsonCommand.php#L269-L271

Added lines #L269 - L271 were not covered by tests
},
$this->reference_map( $translation->getReferences(), $map )
);
Expand Down
101 changes: 0 additions & 101 deletions tests/MakeJsonTest.php

This file was deleted.

14 changes: 0 additions & 14 deletions tests/data/make_json/empty.po

This file was deleted.

29 changes: 0 additions & 29 deletions tests/data/make_json/translations.po

This file was deleted.