diff --git a/composer.json b/composer.json index 7e84726..bade99c 100644 --- a/composer.json +++ b/composer.json @@ -2,24 +2,24 @@ "name": "arcanedev/localization", "description": "Localization Package for Laravel", "keywords": ["arcanedev", "laravel", "localization", "localisation", "i18n"], - "homepage": "https://github.com/ARCANEDEV/Workbench", + "homepage": "https://github.com/ARCANEDEV/Localization", "authors": [ { "name": "ARCANEDEV", "email": "arcanedev.maroc@gmail.com", - "homepage": "https://github.com/ARCANEDEV", + "homepage": "https://github.com/arcanedev-maroc", "role": "Developer" } ], "type": "library", "license": "MIT", "require": { - "php" : ">=5.5.9", - "arcanedev/support": "~3.6.0" + "php" : ">=5.5.9", + "arcanedev/support": "~3.6.0" }, "require-dev": { - "phpunit/phpcov": "~2.0", - "phpunit/phpunit": "~4.0|~5.0" + "phpunit/phpcov": "~2.0", + "phpunit/phpunit": "~4.0|~5.0" }, "autoload": { "psr-4": { diff --git a/src/Middleware/LocaleCookieRedirect.php b/src/Middleware/LocaleCookieRedirect.php index 2fc8bf1..e52977e 100644 --- a/src/Middleware/LocaleCookieRedirect.php +++ b/src/Middleware/LocaleCookieRedirect.php @@ -28,15 +28,18 @@ class LocaleCookieRedirect extends Middleware */ public function handle(Request $request, Closure $next) { - $locale = $request->segment(1, null); + $segment = $request->segment(1, null); + $locale = $request->cookie('locale', null); - if (localization()->isLocaleSupported($locale)) { - cookie('locale', $locale); + if (localization()->isLocaleSupported($segment)) { + cookie('locale', $segment); return $next($request); } - - $locale = $request->cookie('locale', null); + elseif (localization()->isDefaultLocaleHiddenInUrl()) { + $locale = localization()->getDefaultLocale(); + cookie('locale', $locale); + } if (is_string($locale) && ! $this->isDefaultLocaleHidden($locale)) { session()->reflash(); diff --git a/src/Middleware/LocaleSessionRedirect.php b/src/Middleware/LocaleSessionRedirect.php index 3e8f617..ff4730d 100644 --- a/src/Middleware/LocaleSessionRedirect.php +++ b/src/Middleware/LocaleSessionRedirect.php @@ -28,15 +28,18 @@ class LocaleSessionRedirect extends Middleware */ public function handle(Request $request, Closure $next) { - $locale = $request->segment(1, null); + $segment = $request->segment(1, null); + $locale = session('locale', null); - if (localization()->isLocaleSupported($locale)) { - session()->put(compact('locale')); + if (localization()->isLocaleSupported($segment)) { + session()->put(['locale' => $segment]); return $next($request); } - - $locale = session('locale', null); + elseif (localization()->isDefaultLocaleHiddenInUrl()) { + $locale = localization()->getDefaultLocale(); + session()->put(compact('locale')); + } if (is_string($locale) && ! $this->isDefaultLocaleHidden($locale)) { session()->reflash();