Skip to content

Commit

Permalink
Merge pull request #26 from ARCANEDEV/patch-1
Browse files Browse the repository at this point in the history
[#8] Fixing Session & Cookie middleware when the default locale is hidden
  • Loading branch information
arcanedev-maroc committed Jan 8, 2016
2 parents f36711c + 95e2f56 commit 7a3a72a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 8 additions & 5 deletions src/Middleware/LocaleCookieRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 8 additions & 5 deletions src/Middleware/LocaleSessionRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7a3a72a

Please sign in to comment.