我无法在 Laravel 中检索语言环境字符串
I cannot retrieve locale strings in Laravel
出于某种原因 Laravel 不会 return 字符串而只是键:
这是我在 /resources/lang/en/
中保存的 messages.php
return[
'Example' => 'Ejemplo',
'Otroejemplo' => 'Beispiel',
];
这是我的路线:
Route::get('myexample/{locale}', function ($locale) {
App::setLocale($locale);
return view('admin.pages.forms.myexample');
});
这是myexample.blade.php:
@lang('messages.Example');
我希望在打开 localhost:8000/myexample/en 时在 return 中得到 Ejemplo,但我得到的却是 message.Example。
测试了你的代码,它工作正常我遇到的唯一问题是
Route::get('myexample/{locale}', function ($locale) {
App::setLocale($locale);
return view('admin.pages.forms.myexample');
});
使用
Route::get('myexample/{locale}', function ($locale) {
App::setLocale($locale);
return view('myexample'); // in case your view is in resources folder
});
出于某种原因 Laravel 不会 return 字符串而只是键:
这是我在 /resources/lang/en/
中保存的 messages.phpreturn[
'Example' => 'Ejemplo',
'Otroejemplo' => 'Beispiel',
];
这是我的路线:
Route::get('myexample/{locale}', function ($locale) {
App::setLocale($locale);
return view('admin.pages.forms.myexample');
});
这是myexample.blade.php:
@lang('messages.Example');
我希望在打开 localhost:8000/myexample/en 时在 return 中得到 Ejemplo,但我得到的却是 message.Example。
测试了你的代码,它工作正常我遇到的唯一问题是
Route::get('myexample/{locale}', function ($locale) {
App::setLocale($locale);
return view('admin.pages.forms.myexample');
});
使用
Route::get('myexample/{locale}', function ($locale) {
App::setLocale($locale);
return view('myexample'); // in case your view is in resources folder
});