From 8d59c9bf3b8eb7b277d519fdcf5a02632959ca9a Mon Sep 17 00:00:00 2001 From: Jordy Van der Haegen Date: Wed, 26 Nov 2025 21:54:27 +0100 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20load=20=C6=92ramework=20translation?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TranslationLoaderServiceProvider.php | 5 ++++- tests/Feature/TranslationTest.php | 26 ++++++++++++++++++++++++ tests/fixtures/lang/en/validation.php | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/TranslationLoaderServiceProvider.php b/src/TranslationLoaderServiceProvider.php index 09267fc..a0570e6 100644 --- a/src/TranslationLoaderServiceProvider.php +++ b/src/TranslationLoaderServiceProvider.php @@ -46,7 +46,10 @@ protected function registerLoader(): void $this->app->singleton('translation.loader', function ($app) { $aggregateLoader = config('translation-loader.aggregate_loader') ?? AggregateLoader::class; - return new $aggregateLoader($app['files'], $app['path.lang']); + return new $aggregateLoader($app['files'], [ + base_path('vendor/laravel/framework/src/Illuminate/Translation/lang'), + $app['path.lang'], + ]); }); } diff --git a/tests/Feature/TranslationTest.php b/tests/Feature/TranslationTest.php index ee4339c..07dc335 100644 --- a/tests/Feature/TranslationTest.php +++ b/tests/Feature/TranslationTest.php @@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\ValidationException; +use Orchestra\Testbench\Attributes\UsesVendor; final class TranslationTest extends TestCase { @@ -244,4 +245,29 @@ public function it_wont_call_the_missing_key_callback_when_the_translation_exist $this->assertEquals('en value', trans('file.key')); } + + #[Test] + #[UsesVendor] + public function it_can_load_default_file_translations_from_the_framework(): void + { + // When using the UsesVendor attribute, refresh the application to prevent container resolution errors, + // such as "Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist". + $this->refreshApplication(); + + $this->assertEquals(trans('auth.password'), 'The provided password is incorrect.'); + $this->assertEquals(trans('pagination.next'), 'Next »'); + $this->assertEquals(trans('passwords.reset'), 'Your password has been reset.'); + $this->assertEquals(trans('validation.accepted'), 'The :attribute field must be accepted.'); + } + + #[Test] + #[UsesVendor] + public function it_can_override_default_file_translations_from_the_framework(): void + { + // When using the UsesVendor attribute, refresh the application to prevent container resolution errors, + // such as "Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist". + $this->refreshApplication(); + + $this->assertEquals(trans('validation.active_url'), 'Custom - The :attribute field must be a valid URL.'); + } } diff --git a/tests/fixtures/lang/en/validation.php b/tests/fixtures/lang/en/validation.php index 1c62b1a..4b7e2ab 100644 --- a/tests/fixtures/lang/en/validation.php +++ b/tests/fixtures/lang/en/validation.php @@ -2,4 +2,5 @@ return [ 'required' => 'The :attribute field is required.', + 'active_url' => 'Custom - The :attribute field must be a valid URL.', ]; From 5f7f448530c6b8403d584ae6d04af4643c8c0f6c Mon Sep 17 00:00:00 2001 From: Jordy Van der Haegen Date: Wed, 26 Nov 2025 22:41:48 +0100 Subject: [PATCH 2/3] tests: UsesVendor attribute only available in testbench 8.27.0 https://github.com/orchestral/testbench-core/releases/tag/v8.27.0 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 343bda7..26880e5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: - laravel: 11.* testbench: ^9.9 - laravel: 10.* - testbench: 8.* + testbench: ^8.27.0 exclude: - laravel: 12.* php: 8.1 From e166a52f7ffc357d574f0223e37e2c4438941a53 Mon Sep 17 00:00:00 2001 From: Jordy Van der Haegen Date: Wed, 26 Nov 2025 22:42:17 +0100 Subject: [PATCH 3/3] tests: swap actual and expected in the correct order --- tests/Feature/TranslationTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Feature/TranslationTest.php b/tests/Feature/TranslationTest.php index 07dc335..ace776c 100644 --- a/tests/Feature/TranslationTest.php +++ b/tests/Feature/TranslationTest.php @@ -254,10 +254,10 @@ public function it_can_load_default_file_translations_from_the_framework(): void // such as "Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist". $this->refreshApplication(); - $this->assertEquals(trans('auth.password'), 'The provided password is incorrect.'); - $this->assertEquals(trans('pagination.next'), 'Next »'); - $this->assertEquals(trans('passwords.reset'), 'Your password has been reset.'); - $this->assertEquals(trans('validation.accepted'), 'The :attribute field must be accepted.'); + $this->assertEquals('The provided password is incorrect.', trans('auth.password')); + $this->assertEquals('Next »', trans('pagination.next')); + $this->assertEquals('Your password has been reset.', trans('passwords.reset')); + $this->assertEquals('The :attribute field must be accepted.', trans('validation.accepted')); } #[Test] @@ -268,6 +268,6 @@ public function it_can_override_default_file_translations_from_the_framework(): // such as "Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist". $this->refreshApplication(); - $this->assertEquals(trans('validation.active_url'), 'Custom - The :attribute field must be a valid URL.'); + $this->assertEquals('Custom - The :attribute field must be a valid URL.', trans('validation.active_url')); } }