I'm going crazy with Laravel's localization system, but I don't know what's wrong with my code.
I just wrote a language-chooser, in the Head of the document you'll see a function to get the Browser-default language, which shall get the default language.
The Language-Templates are saved as default in an array in the /resources/lang/*language*/messages.php-files.
I really need your help, because I can't see any errors.
<html>
<head>
<?php
//get Browser default language
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
App::setlocale($lang);
?>
</head>
<body>
<div class="container">
@yield('content')
<div class="well text-center">
<h1><?php echo trans('Welcome') ?></h1>
</div>
@section('content.welcome')
<div class="row text-center">
<a href="<?php App::setlocale("de") ?>">Deutsch</a>
<label> | </label>
<a href="<?php App::setlocale("en") ?>">English</a>
<label> | </label>
<a href="<?php App::setlocale("it") ?>">Italiano</a>
<label> | </label>
<a href="<?php App::setlocale("es") ?>">Español</a>
<label> | </label>
<a href="<?php App::setlocale("fr") ?>">Français</a>
<label> | </label>
<a href="<?php App::setlocale("jp") ?>">日本人</a>
<label> | </label>
<a href="<?php App::setlocale("ru") ?>">Pусский</a>
</div>
@show
</div>
@section('footer')
<nav>
<a href="#"> © <?php echo date("Y"); ?></a>
<ul >
<li >
<a href="#"><?php echo trans('Contact') ?></a>
</li>
</ul>
</nav>
@show
</body>
As per my understand, you need to modify your current approach. So, here is the example you can utilize for project.
.Env
config/app.php
HTML
Route
LanguageController
LocaleMiddleware
add middleware to
kernel.php
And Finally , my lang folder looks like
and each folder contains:
Hope, this example help you much, but however it's just a example still you can update as per your requirement. If still something confused please let me know, I will try to update question in further detail.