Skip to content

Commit

Permalink
Allow locales helper to overwrite the supported locales
Browse files Browse the repository at this point in the history
  • Loading branch information
chinleung committed Aug 6, 2019
1 parent e576d3a commit 13cf50b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
/**
* Retrieve the supported locales of the application.
*
* @param array $locales
* @return array
*/
function locales() : array
function locales(array $locales = null) : array
{
if (! is_null($locales)) {
config([
'app.locales' => $locales,
'locales.supported' => $locales,
]);
}

return config('app.locales') ?? config('locales.supported');
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ public function the_locale_helper_will_not_update_if_locale_is_not_supported() :
$this->assertEquals('en', locale());
}

/**
* The locales helper can set the list of supported locales.
*
* @test
* @return void
*/
public function the_locales_helper_can_update_the_list_of_supported_locales() : void
{
$this->assertCount(1, locales());

locales($supported = ['en', 'fr']);

$this->assertEquals($supported, locales());
}

/**
* Retrieve the package providers of the application.
*
Expand Down

0 comments on commit 13cf50b

Please sign in to comment.