Skip to content

Commit

Permalink
feat: add setValidLocales()
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 27, 2023
1 parent dd4e542 commit a86bf1a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,18 @@ public function setLocale(string $locale)
return $this;
}

/**
* Set the valid locales.
*
* @return $this
*/
public function setValidLocales(array $locales)
{
$this->validLocales = $locales;

return $this;
}

/**
* Gets the current locale, with a fallback to the default
* locale if none is set.
Expand Down
15 changes: 15 additions & 0 deletions tests/system/HTTP/IncomingRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ public function testSetBadLocale()
$this->assertSame('es', $request->getLocale());
}

public function testSetValidLocales()
{
$config = new App();
$config->supportedLocales = ['en', 'es'];
$config->defaultLocale = 'es';
$config->baseURL = 'http://example.com/';

$request = new IncomingRequest($config, new URI(), null, new UserAgent());

$request->setValidLocales(['ja']);
$request->setLocale('ja');

$this->assertSame('ja', $request->getLocale());
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/2774
*/
Expand Down

0 comments on commit a86bf1a

Please sign in to comment.