Skip to content

Commit f1e8aa3

Browse files
committed
Translate full URI that contains a placeholder
1 parent 82d08f5 commit f1e8aa3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Macros/UriTranslationMacro.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public static function register()
1818
Lang::macro('uri', function ($uri, $locale = null, $namespace = null) {
1919

2020
// Attempt to translate full uri.
21-
if (!Str::contains($uri, '{') && Lang::has(($namespace ? $namespace.'::' : '')."routes.$uri", $locale)) {
21+
if (Lang::has(($namespace ? $namespace.'::' : '')."routes.$uri", $locale)) {
2222
return Lang::get(($namespace ? $namespace.'::' : '')."routes.$uri", [], $locale);
2323
}
24-
24+
2525
// Split the URI into a Collection of segments.
2626
$segments = new Collection(explode('/', trim($uri, '/')));
2727

tests/Unit/Macros/UriTranslationMacroTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ public function you_can_translate_a_full_uri()
9393
$this->assertEquals('producten/glazen', Lang::uri('products/glass', 'nl'));
9494
}
9595

96+
/** @test */
97+
public function you_can_translate_a_full_uri_with_placeholder()
98+
{
99+
$this->setTranslations([
100+
'nl' => [
101+
'glass' => 'glas',
102+
'products' => 'producten',
103+
'products/glass/{type}' => 'producten/glazen/{type}'
104+
]
105+
]);
106+
107+
$this->assertEquals('producten/glazen/{type}', Lang::uri('products/glass/{type}', 'nl'));
108+
}
109+
96110
/** @test */
97111
public function you_can_specify_a_namespace()
98112
{

0 commit comments

Comments
 (0)