Skip to content

Commit

Permalink
Merge pull request #20 from Laravel-Lang/1.x
Browse files Browse the repository at this point in the history
Added new options for `laravel-lang/routes`
  • Loading branch information
andrey-helldar authored Jun 17, 2024
2 parents 944e073 + 893ef5a commit 401350e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
16 changes: 16 additions & 0 deletions config/public.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],

/*
Expand Down
4 changes: 3 additions & 1 deletion src/Data/Shared/RoutesData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class RoutesData
{
public function __construct(
public RouteNameData $names
public RouteNameData $names,
public string $namePrefix,
public bool $redirect,
) {}
}
6 changes: 4 additions & 2 deletions src/Services/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/SharedWithEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/SharedWithoutEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 401350e

Please sign in to comment.