Fix determining URL with language preferred

This commit is contained in:
printempw 2017-05-06 21:50:17 +08:00
parent 48c8aeb6ff
commit 2ed5dad582

View File

@ -8,11 +8,18 @@
<ul class="dropdown-menu" role="menu">
@foreach(config('locales') as $code => $langInfo)
@if (!isset($langInfo['alias']))
@if (count($_GET) == 0 || (count($_GET) == 1 && isset($_GET['lang'])))
<li class="locale"><a href="?lang={{ $code }}">{{ $langInfo['name'] }}</a></li>
@else
<li class="locale"><a href="{{ $_SERVER['REQUEST_URI'] }}&lang={{ $code }}">{{ $langInfo['name'] }}</a></li>
@endif
<?php
if (count($_GET) == 0) {
$link = "?lang=$code";
} elseif(isset($_GET['lang'])) {
$link = str_replace("lang={$_GET['lang']}", "lang=$code", $_SERVER['REQUEST_URI']);
} else {
$link = $_SERVER['REQUEST_URI']."&lang=$code";
}
?>
<li class="locale">
<a href="{{ $link }}">{{ $langInfo['name'] }}</a>
</li>
@endif
@endforeach
</ul>