-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3563e5
commit 9986251
Showing
11 changed files
with
160 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelLang\Routes\Helpers; | ||
|
||
use LaravelLang\Config\Facades\Config; | ||
|
||
class Route | ||
{ | ||
public static function prefix(): string | ||
{ | ||
return Config::shared()->routes->namePrefix; | ||
} | ||
|
||
public static function redirect(): bool | ||
{ | ||
return Config::shared()->routes->redirect; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelLang\Routes\Middlewares; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Str; | ||
use LaravelLang\Routes\Helpers\Route; | ||
|
||
class LocalizationByParameterPrefix extends LocalizationByParameterWithRedirect | ||
{ | ||
protected function parameters(Request $request): array | ||
{ | ||
return Arr::except($request->route()?->parameters() ?? [], [ | ||
$this->names()->parameter, | ||
]); | ||
} | ||
|
||
protected function routeName(Request $request): ?string | ||
{ | ||
if ($name = $request->route()?->getName()) { | ||
return Str::after($name, $this->routePrefix()); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected function routePrefix(): string | ||
{ | ||
return Route::prefix(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use LaravelLang\Routes\Helpers\Route as RouteName; | ||
use Tests\Constants\LocaleValue; | ||
|
||
use function Pest\Laravel\getJson; | ||
|
||
test('main without prefix', function () { | ||
$foo = 'test'; | ||
|
||
getJson(route('via.group', compact('foo'))) | ||
->assertSuccessful() | ||
->assertJsonPath($foo, LocaleValue::TranslationFrench); | ||
}); | ||
|
||
test('main locale', function (string $locale) { | ||
$foo = 'test'; | ||
|
||
getJson(route(RouteName::prefix() . 'via.group', compact('foo', 'locale'))) | ||
->assertSuccessful() | ||
->assertJsonPath($foo, LocaleValue::TranslationFrench); | ||
|
||
assertEventDispatched(); | ||
})->with('main-locales'); | ||
|
||
test('aliased locale', function (string $locale) { | ||
$foo = 'test'; | ||
|
||
getJson(route(RouteName::prefix() . 'via.group', compact('foo', 'locale'))) | ||
->assertSuccessful() | ||
->assertJsonPath($foo, LocaleValue::TranslationGerman); | ||
|
||
assertEventDispatched(); | ||
})->with('aliased-locales'); | ||
|
||
test('uninstalled locale', function (string $locale) { | ||
$foo = 'test'; | ||
|
||
getJson(route(RouteName::prefix() . 'via.group', compact('foo', 'locale'))) | ||
->assertRedirectToRoute('via.group', [ | ||
'foo' => $foo, | ||
]); | ||
|
||
assertEventNotDispatched(); | ||
})->with('uninstalled-locales'); | ||
|
||
test('unknown locale', function (int|string $locale) { | ||
$foo = 'test'; | ||
|
||
getJson(route(RouteName::prefix() . 'via.group', compact('foo', 'locale'))) | ||
->assertRedirectToRoute('via.group', [ | ||
'foo' => $foo, | ||
]); | ||
|
||
assertEventNotDispatched(); | ||
})->with('unknown-locales'); |