dpfw3607 2018-08-09 06:14
浏览 466

Laravel本地化翻译不起作用,仅显示默认语言

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀