[英]laravel 5.2 setting default locale in app.php does not work
i want to set the default locale to zh-tw from en, i changed the locale='en' to locale='zh-tw' in \config\app.php,我想将默认语言环境从 en 设置为 zh-tw,我将 \config\app.php 中的 locale='en' 更改为 locale='zh-tw',
'locale' => 'zh-tw',
but the view is keep using 'resources\lang\en',但视图继续使用'resources\lang\en',
i've also tried but all not useful:我也试过但都没有用:
added APP_LOCALE in.env=zh-tw
在
APP_LOCALE in.env=zh-tw
添加了 APP_LOCALE
run php artisan cache:clear
运行
php artisan cache:clear
Why \config\app.php locale setting has no effect and meanless in laravel?为什么 \config\app.php locale 设置在 laravel 中无效且毫无意义?
Except to run setlocale('zh-tw') in every controller or create a middleware to set language, is there any other simplest method to change the default locale in few seconds?除了在每个控制器中运行 setlocale('zh-tw') 或创建一个中间件来设置语言之外,还有其他最简单的方法可以在几秒钟内更改默认语言环境吗?
To set the locale and make it work properly you need to do below configurations:要设置语言环境并使其正常工作,您需要进行以下配置:
1) First make your locale folder inside \resources\lang\YOUR_LOCALE_NAME
. 1)首先在
\resources\lang\YOUR_LOCALE_NAME
中创建您的语言环境文件夹。
2) Then add file messages.php
or as per your need. 2) 然后添加文件
messages.php
或根据您的需要。 which has following structure:它具有以下结构:
<?php
return array(
'welcome' => 'Welcome to our application'
);
3) Then go to \config\app.php
and set the locale as your LOCALE_FOLDER_NAME
. 3) 然后转到
\config\app.php
并将语言环境设置为您的LOCALE_FOLDER_NAME
。
4) Remember to set fallback_locale
in app.php
which will be used in case YOUR_LOCALE_NAME
is not found. 4) 请记住在
app.php
中设置fallback_locale
,以防YOUR_LOCALE_NAME
。
To modify the hideDefaultLocaleInURL
parameter in the config/laravellocalization.php
file.修改
config/laravellocalization.php
文件中的hideDefaultLocaleInURL
参数。
From:从:
'hideDefaultLocaleInURL' => false
'hideDefaultLocaleInURL' => false
To:到:
'hideDefaultLocaleInURL' => true
'hideDefaultLocaleInURL' => true
just go to config/app.php
and look for locale
key and change it whatever you want只需转到
config/app.php
并查找locale
密钥并根据需要进行更改
To fix this you need to do below instructions:要解决此问题,您需要执行以下说明:
First make your locale folder inside \resources\lang\LOCALE_NAME.首先在 \resources\lang\LOCALE_NAME 中创建您的语言环境文件夹。
Then you have to add files which has following structure:然后你必须添加具有以下结构的文件:
<?php return [ 'reset' => 'Your password has been reset,', 'sent' => 'We have emailed your password reset link.', 'throttled' => 'Please wait before retrying.', 'token' => 'This password reset token is invalid.', 'user' => "We can't find a user with that email address;",];
Then you have to go to \config\app.php and set locale as your LOCALE_FOLDER_NAME.然后您必须转到 \config\app.php 并将区域设置设置为您的 LOCALE_FOLDER_NAME。
'locale' => 'LOCALE_NAME', 'locale' => 'LOCALE_NAME',
After this you have to clear your config cache.在此之后你必须清除你的配置缓存。 Go to your terminal and paste this code to clear it.
转到您的终端并粘贴此代码以清除它。
php artisan config:cache php artisan 配置:缓存
*Note: Some times you could get an error like this: *注意:有时您可能会遇到这样的错误:
Illuminate\Contracts\Container\BindingResolutionException
Target class [view.engine.resolver] does not exist.
Just run the following code in the root of your application in your system terminal.只需在系统终端的应用程序根目录中运行以下代码。
composer dump-autoload
php artisan config:cache
command in your root directory of the laravel projectphp artisan config:cache
命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.