routes - yii2 创建翻译后的 URL

标签 routes translation yii2

我需要创建用户友好的 URL,这些 URL 已翻译,但指向与其他语言相同的 Controller 。

例子:

/en/myCar/100 ->/de/meinAuto/100 ->/fr/monVoiture/100

我尝试使用路由,但找不到根据翻译后的 URL 调用 Controller 的方法。

我应该从哪里开始的任何提示?

最佳答案

使用内置功能无法轻松完成,但有人有同样的需求并专门为此编写了一个包:yii2-localeurls .我想这可能就是您要找的:

With this extension you can use URLs that contain a language code like:

/en/some/page
/de/some/page
http://www.example.com/en/some/page
http://www.example.com/de/some/page

You can also configure friendly names if you want:

http://www.example.com/english/some/page
http://www.example.com/deutsch/some/page

The language code is automatically added whenever you create a URL, and read back when a URL is parsed. For best user experience the language is autodetected from the browser settings, if no language is used in the URL. The user can still access other languages, though, simply by calling a URL with another language code.

The last requested language is also persisted in the user session and in a cookie. So if the user tries to access your site without a language code in the URL, he'll get redirected to the language he had used on his last visit.

关于routes - yii2 创建翻译后的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30620404/

相关文章:

ruby - 单一嵌套资源的正确路线

php - Symfony2 翻译添加 Html

php - Yii2:比较密码和重设密码的验证

Yii2 kartik 详细 View 隐藏标签

javascript - 设置路由时 Angular 范围变量会发生变化吗?

ruby-on-rails - 如何在一个 Controller 中创建两个更新操作

macos - Vagrant VirtualBox Cisco AnyConnect 与 VPN 的路由问题

postgresql - 间隔的翻译

ios - 按角度平移点 ios

php - Yii2 - 获取所有唯一模型属性值的最佳方法是什么?