Skip to content

Commit

Permalink
Fix issue on hidden locale clash when first segment is dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCavens committed Nov 2, 2016
1 parent 94aa51f commit f2e1327
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Thinktomorrow/Locale/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public function getSlug($locale = null)
*/
public function isHidden($locale = null)
{
// If a specific locale string is passed we first validate it represents a valid locale
if($locale && !$this->validateLocale($locale)) return false;

$locale = $this->validateLocale($locale) ? $locale : $this->get();

return ($this->hidden_locale == $locale);
Expand Down
19 changes: 19 additions & 0 deletions tests/LocaleUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,23 @@ public function it_can_create_a_named_route_with_multiple_segments()
$this->assertEquals('http://example.be/nl/blue/foo/bar?dazzle=awesome&crazy=vibe', LocaleUrl::route('foo.show',['color' => 'blue','dazzle' => 'awesome','crazy' => 'vibe']));
}

/** @test */
public function it_can_create_a_named_route_with_multiple_segments_for_hidden_locale()
{
app()->bind('Thinktomorrow\Locale\Locale', function ($app) {
return new Locale($app['request'], [
'available_locales' => ['nl', 'fr'],
'fallback_locale' => null,
'hidden_locale' => 'nl'
]);
});

Route::get('{color}/foo/bar',['as' => 'foo.show','uses' => function(){}]);

app()->setLocale('nl');
$this->assertEquals('http://example.be/blue/foo/bar?dazzle=awesome&crazy=vibe', LocaleUrl::route('foo.show',['color' => 'blue','dazzle' => 'awesome','crazy' => 'vibe']));
}



}

0 comments on commit f2e1327

Please sign in to comment.