From a18da6670a7ec21b2a9ae0f03f5c45ae7567c0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20R=C3=BCtter?= Date: Sat, 4 Jul 2026 11:26:39 +0000 Subject: [PATCH] Use the site's lang for translations during generation Co-Authored-By: Claude Fable 5 --- src/Generator.php | 2 +- tests/Localized/GenerateTest.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Generator.php b/src/Generator.php index a4d1593..bf1c9dc 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -429,7 +429,7 @@ protected function updateCurrentSite($site) // Set the locale for dates, carbon, and for the translator. // This is what happens in Statamic's Localize middleware. setlocale(LC_TIME, $site->locale()); - app()->setLocale($site->shortLocale()); + app()->setLocale($site->lang()); } protected function checkConcurrencySupport() diff --git a/tests/Localized/GenerateTest.php b/tests/Localized/GenerateTest.php index 9d46c09..d6be4fa 100644 --- a/tests/Localized/GenerateTest.php +++ b/tests/Localized/GenerateTest.php @@ -47,6 +47,8 @@ protected function tearDown(): void URL::enforceTrailingSlashes(false); URL::clearUrlCache(); + $this->files->delete([lang_path('en_US.json'), lang_path('fr_FR.json')]); + parent::tearDown(); } @@ -312,6 +314,35 @@ public function it_generates_associated_paginated_pages_when_generating_only_loc $this->assertStringContainsString('Prev Link: /fr/le-articles/page/1', $index); } + #[Test] + public function it_translates_using_the_site_lang() + { + Site::setSites([ + 'default' => [ + 'name' => 'English', + 'locale' => 'en_US', + 'lang' => 'en_US', + 'url' => '/', + ], + 'french' => [ + 'name' => 'French', + 'locale' => 'fr_FR', + 'lang' => 'fr_FR', + 'url' => '/fr/', + ], + ]); + + $this->files->put(lang_path('en_US.json'), json_encode(['welcome' => 'Welcome'])); + $this->files->put(lang_path('fr_FR.json'), json_encode(['welcome' => 'Bienvenue'])); + + $this->files->put(resource_path('views/default.antlers.html'), '

{{ trans key="welcome" }}

'); + + $files = $this->generate(); + + $this->assertStringContainsString('

Welcome

', $files['index.html']); + $this->assertStringContainsString('

Bienvenue

', $files['fr/index.html']); + } + #[Test] public function it_enforces_trailing_slashes_when_config_enabled() {