Skip to content

Commit c9bd6a0

Browse files
niels-numbersMarc Cámara
authored andcommitted
Fix hideDefaultLocale (#664)
A previous commit for caching broke the functionality of `hideDefaultLocale`. The purpose of `setLocale` is to return the locale of the url (even if there is none). This is necessary for ensuring that the current requested route actually exists. Therefore this behaviour was reestablished. The same behaviour goes for the cached routes. The file `bootstrap/cache/routes_**.php` imitates the routes from `setLocale`. Therefore, `getCurrentLocale` has to be dismissed. Also a nullable locale should refere to `bootstrap/cache/routes.php` and not an alternative. Fixes #656 Fixes #661
1 parent d228a61 commit c9bd6a0

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

src/Mcamara/LaravelLocalization/LaravelLocalization.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,6 @@ public function setLocale($locale = null)
170170

171171
if (!empty($this->supportedLocales[$locale])) {
172172
$this->currentLocale = $locale;
173-
174-
if ($locale === $this->defaultLocale && $this->hideDefaultLocaleInURL()) {
175-
$locale = null;
176-
}
177-
178173
} else {
179174
// if the first segment/locale passed is not valid
180175
// the system would ask which locale have to take

src/Mcamara/LaravelLocalization/Traits/LoadsTranslatedCachedRoutes.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ protected function loadCachedRoutes()
2222
{
2323
$localization = $this->getLaravelLocalization();
2424

25-
$localization->setLocale();
26-
27-
$locale = $localization->getCurrentLocale();
25+
// compute $locale from url.
26+
// It is null if url does not contain locale.
27+
$locale = $localization->setLocale();
2828

2929
$localeKeys = $localization->getSupportedLanguagesKeys();
3030

@@ -58,11 +58,6 @@ protected function makeLocaleRoutesPath($locale, $localeKeys)
5858
{
5959
$path = $this->getDefaultCachedRoutePath();
6060

61-
// If we have no specifically forced locale, use default or let the request determine it.
62-
if ($locale === null) {
63-
$locale = $this->getLocaleFromRequest();
64-
}
65-
6661
if ( ! $locale || ! in_array($locale, $localeKeys)) {
6762
return $path;
6863
}

0 commit comments

Comments
 (0)