Php 使用翻译在Laravel中进行网站翻译
我是拉拉维尔的初学者。我的项目是在拉威尔7号完成的 我有以下代码: router.phpPhp 使用翻译在Laravel中进行网站翻译,php,laravel,Php,Laravel,我是拉拉维尔的初学者。我的项目是在拉威尔7号完成的 我有以下代码: router.php $locale = App::getLocale(); if (App::isLocale('pl')) { Route::get('/', 'HomeController@index')->name('home'); Route::get('/o-nas', 'HomeController@about')->name('about'); Route::get('/of
$locale = App::getLocale();
if (App::isLocale('pl')) {
Route::get('/', 'HomeController@index')->name('home');
Route::get('/o-nas', 'HomeController@about')->name('about');
Route::get('/oferta', 'HomeController@offer')->name('offer');
Route::get('/realizacje', 'HomeController@realizations')->name('realizations');
Route::get('/kontakt', 'HomeController@contact')->name('contact');
Route::get('/polityka-prywatnosci', 'HomeController@privacyPolicy')->name('privacy-policy');
}
Route::get('/en', 'HomeController@index')->name('home2');
if (App::isLocale('en')) {
Route::get('/en/about-us', 'HomeController@about')->name('about');
Route::get('/en/offer', 'HomeController@offer')->name('offer');
Route::get('/en/realizations', 'HomeController@realizations')->name('realizations');
Route::get('/en/contact', 'HomeController@contact')->name('contact');
Route::get('/en/privacy-policy', 'HomeController@privacyPolicy')->name('privacy-policy');
}
Route::any('{query}',
function() { return redirect('/'); })
->where('query', '.*');
在resources/lang中,我创建2个目录:pl和en,并放置router.php:
return array(
'start' => 'start',
'about' => 'about us',
'offer' => 'offer',
'realizations' => 'realizations',
'contact' => 'contact'
)
在blade中,我创建了以下url:
<ul class="navbar-nav">
<li class="nav-item d-block d-lg-none d-xl-block text-center">
<a class="nav-link active" href="{{ route('home') }}">Start</a>
</li>
<li class="nav-item text-center">
<a class="nav-link" href="{{ route('about') }}">O nas</a>
</li>
<li class="nav-item text-center">
<a class="nav-link" href="{{ route('offer') }}">Oferta</a>
</li>
<li class="nav-item text-center">
<a class="nav-link" href="{{ route('realizations') }}">Realizacje </a>
</li>
<li class="nav-item text-center">
<a class="nav-link" href="{{ route('contact') }}">Kontakt</a>
</li>
<li class="nav-item mx-xl-4 mb-2 mb-md-0 text-center">
<a class="nav-link order-visit" href="{{ route('contact') }}">Zamów wizytę</a>
</li>
<li class="nav-item text-center d-inline-block d-lg-none language-box2">
<a href="{{ route('home') }}">PL</a> | <a href="{{ route('home2') }}">EN</a>
</li>
</ul>
-
-
-
-
-
-
-
|
这个代码对翻译正确吗
我有一个问题,如果不更改语言,我无法访问,例如domain.com/en/contact、domain.com/en/about-us等
如何修复此问题?在路由中,对于exepmle home,请检查lang并重定向
<li class="nav-item d-block d-lg-none d-xl-block text-center">
@if (App::isLocale('pl'))
<a class="nav-link active" href="{{ route('home') }}">Start</a>
@else
<a class="nav-link active" href="{{ route('home2') }}">Start</a>
@endif
</li>
@if(App::isLocale('pl'))
@否则
@恩迪夫