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'), '