Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
31 changes: 31 additions & 0 deletions tests/Localized/GenerateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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'), '<h1>{{ trans key="welcome" }}</h1>');

$files = $this->generate();

$this->assertStringContainsString('<h1>Welcome</h1>', $files['index.html']);
$this->assertStringContainsString('<h1>Bienvenue</h1>', $files['fr/index.html']);
}

#[Test]
public function it_enforces_trailing_slashes_when_config_enabled()
{
Expand Down