Skip to content

Commit

Permalink
[Feature] Exclude subdirectories (#45)
Browse files Browse the repository at this point in the history
* [Feature] Exclude subdirectories

* Fix test
  • Loading branch information
amiranagram authored Nov 8, 2022
1 parent 13e8dee commit 28418e2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ return [
* Directories which should be looked inside.
*/
'dirs' => ['resources/views'],

/**
* Subdirectories which will be excluded.
* The values must be relative to the included directory paths.
*/
'exclude' => [
//
],

/**
* Patterns by which files should be queried.
Expand Down
8 changes: 8 additions & 0 deletions config/localizator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
*/
'dirs' => ['resources/views'],

/**
* Subdirectories which will be excluded.
* The values must be relative to the included directory paths.
*/
'exclude' => [
//
],

/**
* Patterns by which files should be queried.
* The values can be a regular expression, glob, or just a string.
Expand Down
5 changes: 4 additions & 1 deletion src/Services/FileFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public function getFiles(): Collection
}, $this->config['search']['dirs']);

return new Collection(
(new Finder)->in($directories)->name($this->config['search']['patterns'])->files()
(new Finder)->in($directories)
->notPath($this->config['search']['exclude'])
->name($this->config['search']['patterns'])
->files()
);
}
}
30 changes: 30 additions & 0 deletions tests/LocalizatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,34 @@ public function testRemoveMissingKeys(): void
// Cleanup.
self::flushDirectories('lang', 'views');
}

public function testDirectoriesAreBeingExcluded(): void
{
mkdir(resource_path('views/sub1'), 0755);
mkdir(resource_path('views/sub2'), 0755);

$this->createTestView("{{ __('Foo') }}");
$this->createTestView("{{ __('Bar') }}", 'sub1/test');
$this->createTestView("{{ __('Baz') }}", 'sub2/test');

config([
'localizator.sort' => false,
'localizator.search.exclude' => 'sub1',
]);

$this->artisan('localize', ['lang' => 'en']);

// Do created locale files exist?
self::assertJsonLangFilesExist('en');

// Do their contents match the expected results?
$contents = $this->getJsonLangContents('en');
self::assertSame([
'Foo' => 'Foo',
'Baz' => 'Baz',
], $contents);

// Cleanup.
self::flushDirectories('lang', 'views');
}
}

0 comments on commit 28418e2

Please sign in to comment.