Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/Support/AutoDiscoveryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public function langDirectoryFinder(): FinderCollection
return FinderCollection::forDirectories()
->depth(0)
->name('lang')
->inOrEmpty($this->base_path.'/*/resources/');
->inOrEmpty([
$this->base_path.'/*/resources/',
$this->base_path.'/*/',
]);
}

public function listenerDirectoryFinder(): FinderCollection
Expand Down
17 changes: 17 additions & 0 deletions tests/AutoDiscoveryHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ public function test_it_finds_lang_directories(): void
$this->assertContains($this->module2->path('resources/lang'), $resolved);
}

public function test_it_finds_lang_directories_when_they_are_in_the_module_root_directory(): void
{
// These paths don't exist by default
$fs = new Filesystem();
$fs->makeDirectory($this->module1->path('lang'));
$fs->makeDirectory($this->module2->path('lang'));

$resolved = [];

$this->helper->langDirectoryFinder()->each(function(SplFileInfo $directory) use (&$resolved) {
$resolved[] = str_replace('\\', '/', $directory->getPathname());
});

$this->assertContains($this->module1->path('lang'), $resolved);
$this->assertContains($this->module2->path('lang'), $resolved);
}

public function test_it_finds_event_listeners(): void
{
$this->artisan(MakeListener::class, [
Expand Down
24 changes: 24 additions & 0 deletions tests/ModularServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,28 @@ public function test_it_loads_translations_from_module(): void
$this->assertEquals('Test JSON translation', $translator->get('Test JSON string'));
$this->assertEquals('Test PHP translation', $translator->get('test-module::foo.bar'));
}

public function test_it_loads_translations_from_module_when_lang_directory_is_in_module_root_directory(): void
{
$module = $this->makeModule();

$this->filesystem()->ensureDirectoryExists($module->path('lang'));
$this->filesystem()->ensureDirectoryExists($module->path('lang/en'));

$this->filesystem()->put($module->path('lang/en.json'), json_encode([
'Test JSON string' => 'Test JSON translation',
], JSON_THROW_ON_ERROR));

$this->filesystem()->put(
$module->path('lang/en/foo.php'),
'<?php return ["bar" => "Test PHP translation"];'
);

$this->app->setLocale('en');

$translator = $this->app->make('translator');

$this->assertEquals('Test JSON translation', $translator->get('Test JSON string'));
$this->assertEquals('Test PHP translation', $translator->get('test-module::foo.bar'));
}
}
Loading