diff --git a/config/public.php b/config/public.php index 1d8d613..25bb36a 100644 --- a/config/public.php +++ b/config/public.php @@ -114,6 +114,22 @@ 'cookie' => RouteName::Cookie, 'session' => RouteName::Session, ], + + /* + * This option specifies the prefix of route group names. + * + * By default, `localized.` + */ + + 'name_prefix' => env('LOCALIZATION_NAME_PREFIX', 'localized.'), + + /* + * This option specifies the request redirection option when trying to open the default localization. + * + * Applies when using the `LaravelLang\Routes\Facades\LocalizationRoute` facade. + */ + + 'redirect_default' => (bool) env('LOCALIZATION_REDIRECT_DEFAULT', false), ], /* diff --git a/src/Data/Shared/RoutesData.php b/src/Data/Shared/RoutesData.php index 3c1b9b7..b46f570 100644 --- a/src/Data/Shared/RoutesData.php +++ b/src/Data/Shared/RoutesData.php @@ -7,6 +7,8 @@ class RoutesData { public function __construct( - public RouteNameData $names + public RouteNameData $names, + public string $namePrefix, + public bool $redirect, ) {} } diff --git a/src/Services/Config.php b/src/Services/Config.php index 654092e..a832483 100644 --- a/src/Services/Config.php +++ b/src/Services/Config.php @@ -73,12 +73,14 @@ protected function smartPunctuation(): SmartPunctuationData protected function routes(): RoutesData { return new RoutesData( - names: new RouteNameData( + names : new RouteNameData( parameter: $this->value(Name::Shared, 'routes.names.parameter', fallback: 'locale'), header : $this->value(Name::Shared, 'routes.names.header', fallback: RouteName::Header), cookie : $this->value(Name::Shared, 'routes.names.cookie', fallback: RouteName::Cookie), session : $this->value(Name::Shared, 'routes.names.session', fallback: RouteName::Session), - ) + ), + namePrefix: $this->value(Name::Shared, 'routes.name_prefix', fallback: 'localized.'), + redirect : $this->value(Name::Shared, 'routes.redirect_default', fallback: false), ); } diff --git a/tests/Unit/SharedWithEnvTest.php b/tests/Unit/SharedWithEnvTest.php index 16d0af8..79bfc60 100644 --- a/tests/Unit/SharedWithEnvTest.php +++ b/tests/Unit/SharedWithEnvTest.php @@ -81,6 +81,18 @@ ->toBe(config('localization.routes.names.session')); }); +test('routes: name prefix', function () { + expect(Config::shared()->routes->namePrefix) + ->toBeString() + ->toBe(config('localization.routes.name_prefix')); +}); + +test('routes: redirect default', function () { + expect(Config::shared()->routes->redirect) + ->toBeBool() + ->toBe(config('localization.routes.redirect_default')); +}); + test('models', function () { config()->set(Name::Shared() . '.models.connection', 'foo'); config()->set(Name::Shared() . '.models.table', 'bar'); diff --git a/tests/Unit/SharedWithoutEnvTest.php b/tests/Unit/SharedWithoutEnvTest.php index 16d0af8..79bfc60 100644 --- a/tests/Unit/SharedWithoutEnvTest.php +++ b/tests/Unit/SharedWithoutEnvTest.php @@ -81,6 +81,18 @@ ->toBe(config('localization.routes.names.session')); }); +test('routes: name prefix', function () { + expect(Config::shared()->routes->namePrefix) + ->toBeString() + ->toBe(config('localization.routes.name_prefix')); +}); + +test('routes: redirect default', function () { + expect(Config::shared()->routes->redirect) + ->toBeBool() + ->toBe(config('localization.routes.redirect_default')); +}); + test('models', function () { config()->set(Name::Shared() . '.models.connection', 'foo'); config()->set(Name::Shared() . '.models.table', 'bar');