我的网站有三种语言‘英语’,‘波斯语’,‘阿拉伯语’。
例如:
在Request中
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'mobile' => 'required|max:11|min:11',
'register_id' => 'required|max:7|min:7'
];
}我希望在用户选择语言之后,在所选语言中显示一条错误消息。
我该怎么办?
发布于 2016-10-25 22:52:21
如果您想在laravel应用程序中使用不同的语言,那么您可以使用内置的本地化:
https://laravel.com/docs/5.2/localization
编辑:
为了你的目的,我会这样对待它。
首先,在resources/lang中创建语言文件夹,例如,对于您的阿拉伯语消息,您将在resource/lang/ar中放置一个messages.php。
我不知道您是如何存储用户语言的,所以我假设它以lang的形式存储在会话中。
现在您可以创建中间件来检查用户选择的语言并设置区域设置:
public function handle($request, Closure $next)
{
// set language from session
\App::setLocale(session('lang'));
return $next($request);
}现在将其注册为全局中间件:app\Kernal.php
现在,您的app应该根据会话中的'lang‘值在每个请求之前自动设置区域设置。确保您有fallback_locale设置,以便您的应用程序知道如何做,如果您的用户没有一个地区设置。
https://stackoverflow.com/questions/40250911
复制相似问题