Laravel 更改语言环境不起作用

2022-01-11 00:00:00 localization php laravel

我正在使用由英语和荷兰语组成的语言下拉列表.

I am using a dropdown lists for the languages, consisting of english and dutch.

<form class="" action="{{url('/locale')}}" method="post">
            Locale:
              <select class="" name="locale" onchange="this.form.submit()">

                <option value="en" >English</option>
                <option value="du" >Dutch</option>
              </select>
          </form>

那么这是我的 routes.php,

Then this is my routes.php,

Route::post('/locale', function(){

     App::setLocale(Request::Input('locale'));

     return redirect()->back();
});

而且它不工作.

在我的项目中,路径是这样的

In my project, the path is like this

resources/
 /du
   navigation.php
 /en
  /navigation.php

来自荷兰语(du) 'navigation.php'

From the Dutch(du) 'navigation.php'

<?php
return [
  "home" => 'Home-test-dutch',  
];

对于英语(en)'navigation.php'

and for the English(en) 'navigation.php'

<?php
return [
  "home" => 'Home',  
];

推荐答案

我从这篇文章中解决了我的问题 https://mydnic.be/post/laravel-5-and-his-fcking-non-persistent-app-setlocale

I solved my problem from this article https://mydnic.be/post/laravel-5-and-his-fcking-non-persistent-app-setlocale

感谢贡献非持久"一词的人们

Thanks to the people who contributed the word 'non persistent'

相关文章