我正在构建一个laravel应用程序。我正在构建一个多语言应用程序,它将具有法语和西班牙语,其URL将是
www.example.com/fr/route/slug for french
www.example.com/es/route/slug for spanish
www.example.com/route/slug for english which is the main one
但是我很困惑,我应该如何在同一种语言中保持从一个URL到另一个URL的一致性,即当我点击法语链接时,应该返回的应该仍然是法语。例如:
from
www.example.com/fr/route/slug1 to
www.example.com/fr/route/another_path to
www.example.com/fr/route/final_path which would be maintaing same language path
www.example.com/es/route/slug1 to
www.example.com/es/route/another_path to
www.example.com/es/route/final_path for spanish
www.example.com/route/slug1 to
www.example.com/route/another_path to
www.example.com/route/final_path for english
当我从例如法语到英语页面必须一致,例如
www.example.com/fr/route/slug1 to
www.example.com/fr/route/another_path in french to english
www.example.com/route/another_path
我应该采取哪些步骤?任何帮助,将不胜感激。提前致谢。
为了保持这一点,您可以按照以下步骤操作:
您应该为所有路线添加此组
Route::group(['middlewareGroups' => 'web', 'prefix' => '{local}'], function () {
然后制作中间件,然后抓住本地,然后:
public function handle($request, Closure $next)
{
App::setLocale($locale);
}
并通过将其添加到位于Http / kernel.php文件中的$ middleware数组中来应用它