Skip to content

Commit

Permalink
Adding support to localize relative URLs (aka URI / path)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Sep 25, 2015
1 parent d8bd6ca commit 48227cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ public function getLocalizedURL($locale = null, $url = null, $attributes = [])
return $url;
}

if (empty($url)) {
$url = $parsedUrl['path'];
}

return $this->createUrlFromUri($url);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/LocalizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,24 @@ public function it_can_get_all_locales()
$this->assertEquals(289, $locales->count());
}

/** @test */
public function it_can_get_localized_url_with_relative_urls()
{
$urls = [
'/contact',
'/contact/',
$this->testUrlOne . '/contact',
$this->testUrlOne . '/contact/'
];

foreach ($urls as $url) {
$this->assertEquals(
$this->testUrlOne . 'en/contact',
localization()->LocalizeURL($url)
);
}
}

/** @test */
public function it_can_use_facade()
{
Expand Down

0 comments on commit 48227cf

Please sign in to comment.