I'm trying to build multilingual website with laravel but there is a problem with translation. It shows only default language. Even if I set the app locale language, laravel continue to shows default language
when I said app.test/ar/admin
or app.test/en/admin
, routes and others works as well, I can reach the view, just trans message not work..
admin blade
<div class="row">
<h1>{{trans('admin.welcome')}}</h1>
</div>
I tried with __('admin.welcome')
but still same result..
app service provider;
public function boot(Request $request)
{
if (!session()->has("locale")) {
session()->put("locale", $request->getPreferredLanguage(config("translatable.locales")));
}
app()->setLocale(session()->get("locale"));
}
route service provider
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
'prefix' => session()->get("locale"),
], function ($router) {...});
language middleware
public function handle(Request $request, Closure $next)
{
if (!in_array($request->segment(1), config('translatable.locales'))) {
$segments = $request->segments();
$segments = array_prepend($segments, app()->getLocale());
return redirect()->to(implode('/', $segments));
}
return $next($request);
}
folder structure
--en
+admin.php
+auth.php
+pagination.php
+passwords.php
+validation.php
--ar
+admin.php
+auth.php
+pagination.php
+passwords.php
+validation.php
so how can I fix this ? Any help would be appreciated.