Skip to content

Commit

Permalink
Attempt to translate full uri + link fixed in README (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
kedniko authored Dec 19, 2021
1 parent af695ff commit 1617291
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ Check out the [Laravel docs](https://laravel.com/docs/urls#signed-urls) for more

### 🌎 Translate Routes

If you want to translate the segments of your URI's, create a `routes.php` language file for each locale you [configured](#configure-supported-locales):
If you want to translate the segments of your URI's, create a `routes.php` language file for each locale you [configured](#%EF%B8%8F-supported-locales):

```
resources
Expand Down
6 changes: 6 additions & 0 deletions src/Macros/UriTranslationMacro.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class UriTranslationMacro
public static function register()
{
Lang::macro('uri', function ($uri, $locale = null) {

// Attempt to translate full uri.
if (!Str::contains($uri, '{') && Lang::has("routes.$uri", $locale)) {
return Lang::get("routes.$uri", [], $locale);
}

// Split the URI into a Collection of segments.
$segments = new Collection(explode('/', trim($uri, '/')));

Expand Down

0 comments on commit 1617291

Please sign in to comment.