-
-
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.
Merge pull request #20 from Laravel-Lang/1.x
Replaced the UrlGenerator override with the `localizedRoute` method
- Loading branch information
Showing
7 changed files
with
76 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Support\Facades\Route; | ||
use Illuminate\Support\Str; | ||
use LaravelLang\Config\Facades\Config; | ||
|
||
if (! function_exists('localizedRoute')) { | ||
function localizedRoute(string $route, array $parameters = [], bool $absolute = true): string | ||
{ | ||
$locale = Config::shared()->routes->names->parameter; | ||
$prefix = Config::shared()->routes->namePrefix; | ||
|
||
$name = Str::start($route, $prefix); | ||
|
||
if (! Route::has($name)) { | ||
return route($route, $parameters, $absolute); | ||
} | ||
|
||
return route($name, array_merge([ | ||
$locale => app()->getLocale(), | ||
], $parameters), $absolute); | ||
} | ||
} |
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,18 @@ | ||
{ | ||
"$schema": "https://laravel-ide.com/schema/laravel-ide-v2.json", | ||
"completions": [ | ||
{ | ||
"complete": "routeName", | ||
"condition": [ | ||
{ | ||
"functionNames": [ | ||
"localizedRoute" | ||
], | ||
"parameters": [ | ||
1 | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
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 was deleted.
Oops, something went wrong.
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use LaravelLang\Config\Facades\Config; | ||
use Tests\Constants\LocaleValue; | ||
|
||
test('route groups', function () { | ||
$name = Config::shared()->routes->namePrefix; | ||
$locale = LocaleValue::LocaleMain; | ||
$fallback = LocaleValue::LocaleAliasParent; | ||
|
||
expect(localizedRoute($name . 'via.group.facade', ['foo' => 'bar'])) | ||
->toEndWith("localhost/$locale/group/facade/bar"); | ||
|
||
expect(localizedRoute($name . 'via.group.macro', ['foo' => 'bar', 'locale' => $fallback])) | ||
->toEndWith("localhost/$fallback/group/macro/bar"); | ||
|
||
expect(localizedRoute('via.group.facade', ['foo' => 'bar'])) | ||
->toEndWith("localhost/$locale/group/facade/bar"); | ||
|
||
expect(localizedRoute('via.group.macro', ['foo' => 'bar', 'locale' => $fallback])) | ||
->toEndWith("localhost/$fallback/group/macro/bar"); | ||
}); | ||
|
||
test('routes without groups', function () { | ||
expect(localizedRoute('via.model.default', ['foo' => 'bar'])) | ||
->toEndWith('localhost/model/default/bar'); | ||
}); |
This file was deleted.
Oops, something went wrong.