diff --git a/src/Support/AutoDiscoveryHelper.php b/src/Support/AutoDiscoveryHelper.php index a59996e..19efdee 100644 --- a/src/Support/AutoDiscoveryHelper.php +++ b/src/Support/AutoDiscoveryHelper.php @@ -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 diff --git a/tests/AutoDiscoveryHelperTest.php b/tests/AutoDiscoveryHelperTest.php index 4f4a55b..a33d24e 100644 --- a/tests/AutoDiscoveryHelperTest.php +++ b/tests/AutoDiscoveryHelperTest.php @@ -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, [ diff --git a/tests/ModularServiceProviderTest.php b/tests/ModularServiceProviderTest.php index 5d4c74f..72e99d2 100644 --- a/tests/ModularServiceProviderTest.php +++ b/tests/ModularServiceProviderTest.php @@ -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'), + ' "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')); + } }