Skip to content

Commit

Permalink
Add getLocale() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Oct 27, 2023
1 parent 9547650 commit d76c92d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ViewTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ public function withLocale(string $locale): static
return $new;
}

/**
* Get the specified locale code.
*
* @return string The locale code.
*/
public function getLocale(): string
{
return $this->localeState->getLocale();
}

/**
* Gets the base path to the view directory.
*
Expand Down
11 changes: 11 additions & 0 deletions tests/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,17 @@ public function testImmutability(): void
$this->assertNotSame($view, $view->withFallbackExtension('tpl'));
}

public function testGetLocale()
{
$view = TestHelper::createView();

$this->assertSame('en', $view->getLocale());

$view->setLocale('en-US');

$this->assertSame('en-US', $view->getLocale());
}

private function createViewWithBasePath(string $basePath): View
{
return new View($basePath, new SimpleEventDispatcher());
Expand Down

0 comments on commit d76c92d

Please sign in to comment.