Skip to content

Commit

Permalink
When i18n provider is enabled, avoid locale less url
Browse files Browse the repository at this point in the history
  • Loading branch information
ehibes committed Feb 3, 2016
1 parent e113772 commit fa5119f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ $app = new Application();
//...
$app->register(new Jenyak\I18nRouting\Provider\I18nRoutingServiceProvider());
$app['locale'] = 'en';
$app['i18n_routing.locales'] = array('en', 'hu', 'ua');
$app['i18n_routing.locales'] = array('en', 'eu', 'fr');

// You can translate patterns
$app['translator.domains'] = array('routes' => array(
'hu' => array('test_route' => '/teszt'),
'fr' => array('test_route' => '/entsegu-bat'),
));

// There's no need to put {_locale} in route pattern
Expand All @@ -54,11 +54,11 @@ $app->get('/test', function () {
```
Matched URLs will be:

`/test` - url for default locale without prefix
`/en/test` - url for default locale without prefix

`/hu/teszt` - url with prefix and translated
`/eu/entsegu-bat` - url with prefix and translated

`/ua/test` - url with prefix
`/fr/test` - url with prefix

# Disable I18n for a route
```php
Expand Down
4 changes: 1 addition & 3 deletions src/Jenyak/I18nRouting/I18nControllerCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public function generateI18nPatterns($routeName, Route $route)
$i18nPattern = $route->getPath();
}

if ($this->defaultLocale !== $locale) {
$i18nPattern = '/'.$locale.$i18nPattern;
}
$i18nPattern = '/'.$locale.$i18nPattern;

$patterns[$i18nPattern][] = $locale;
}
Expand Down
5 changes: 3 additions & 2 deletions tests/I18nRoutingServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function testDefaultLocaleI18nRoutes()
return 'ok';
})->bind('test');

$this->assertEquals(200, $app->handle(Request::create('/test'))->getStatusCode());
$this->assertEquals(404, $app->handle(Request::create('/test'))->getStatusCode());
$this->assertEquals(200, $app->handle(Request::create('/en/test'))->getStatusCode());
}

public function testDefaultLocaleWithPrefixI18nRoutes()
Expand All @@ -45,7 +46,7 @@ public function testDefaultLocaleWithPrefixI18nRoutes()
return 'ok';
});

$this->assertEquals(404, $app->handle(Request::create('/en/'))->getStatusCode());
$this->assertEquals(200, $app->handle(Request::create('/en/'))->getStatusCode());
}

public function testNonDefaultLocaleI18nRoutes()
Expand Down

0 comments on commit fa5119f

Please sign in to comment.