我正在进行本地化并使用{{trans('pro.alert.error')}}
在我的php中,现在我想在js文件中使用它也在那里工作怎么写那里
我在.php文件中使用相同的
$('#msg-text').html('{{trans('pro.alert.error')}}');
这里的工作正常但不是.js
我的 js 代码为
invalidHandler: function(e, t) {
$('#msg-text').html('You have errors');
},
我想将html中的此文字更改为{{trans('pro.alert.error')}}
但它不在这里工作
请帮助解决问题
答案 0 :(得分:0)
您的代码将是:
invalidHandler: function(e, t) {
$('#msg-text').html("{{ trans('pro.alert.error') }}");
},
如果您想在.js文件中使用它,可以使用:
Route::get('/myfile.js', 'JSController@customJS');
控制器: public function customJS(){ return view('js.custom'); }
查看:
$('#msg-text').html("{{ trans('pro.alert.error') }}");
当您在代码中包含<script src="{{ asset('/myfile.js') }}"></script>
时,这应该有效!
希望这有效!
答案 1 :(得分:0)
不要混用JS和PHP。我建议您将翻译放入隐藏的输入中:
{!! Form::hidden('error', trans('app.you-have-errors')) !!}
然后在JS中获取这些数据:
$('#msg-text').html($('[name="error"]').value());