Laravel 设置默认语言不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47784255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:05:45  来源:igfitidea点击:

Laravel set default language not working

phplaravellocalization

提问by Q8root

I have changed the default website localization in confing/app.php to be (de)

我已将 confing/app.php 中的默认网站本地化更改为 (de)

'locale' => 'de',
'fallback_locale' => 'de',

But still website is loading in 'en' localization .

但网站仍在“en”本地化中加载。

I tried clearing the view cache and cache but nothing changed .

我尝试清除视图缓存和缓存,但没有任何改变。

I am using https://github.com/mcamara/laravel-localization

我正在使用 https://github.com/mcamara/laravel-localization

The de will be activate only when i use the URL domainname.com/de

只有当我使用 URL domainname.com/de 时才会激活 de

回答by lagbox

In the scenario to not be using the dynamic locale in the URL it seems you will have to adjust the configuration file for this package:

在不使用 URL 中的动态语言环境的情况下,您似乎必须调整此包的配置文件:

'useAcceptLanguageHeader' => false,

From the comments for that variable:

从该变量的评论:

"Negotiate for the user locale using the Accept-Language header if it's not defined in the URL? If false, system will take app.php locale attribute"

“如果 URL 中未定义,请使用 Accept-Language 标头协商用户语言环境?如果为 false,系统将采用 app.php 语言环境属性”

Seems to get it to use that default you have to set this to false.

似乎让它使用该默认值,您必须将其设置为 false。

You could play with the other variable:

你可以玩另一个变量:

'hideDefaultLocaleInURL' => true,

to see how that adjusts the default behavior as well.

看看它是如何调整默认行为的。

回答by Ayman Elshehawy

try to add __construct() function to your controller. :)

尝试将 __construct() 函数添加到您的控制器中。:)

public function __construct(){}