Skip to content

Commit

Permalink
Allow set current locale via config
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed May 15, 2023
1 parent 3743aff commit 6db8dea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ Language Config Options
'language' => [
'default' => [
'default' => 'en',
'current' => 'en',
'supported' => null,
'negotiate' => false,
'request_instance' => 'default',
Expand All @@ -703,6 +704,11 @@ default

Sets the default language code. The default is ``en``.

current
"""""""

Sets the current language code. The default is ``en``.

supported
"""""""""

Expand Down
3 changes: 3 additions & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,9 @@ protected static function setLanguage(string $instance) : Language
{
$config = static::config()->get('language', $instance);
$service = new Language($config['default'] ?? 'en');
if (isset($config['current'])) {
$service->setCurrentLocale($config['current']);
}
if (isset($config['supported'])) {
$service->setSupportedLocales($config['supported']);
}
Expand Down
1 change: 1 addition & 0 deletions tests/configs/language.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
return [
'default' => [
'default' => 'en',
'current' => 'en',
'supported' => [
'en',
'es',
Expand Down

0 comments on commit 6db8dea

Please sign in to comment.