diff --git a/src/Support/FinderFactory.php b/src/Support/FinderFactory.php index b3c74b4..130dbf1 100644 --- a/src/Support/FinderFactory.php +++ b/src/Support/FinderFactory.php @@ -83,7 +83,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/FinderFactoryTest.php b/tests/FinderFactoryTest.php index 7f3f2d7..28a6c39 100644 --- a/tests/FinderFactoryTest.php +++ b/tests/FinderFactoryTest.php @@ -170,6 +170,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 fb12555..2c8f48e 100644 --- a/tests/ModularServiceProviderTest.php +++ b/tests/ModularServiceProviderTest.php @@ -164,4 +164,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')); + } }