【发布时间】:2015-07-06 06:30:05
【问题描述】:
我在 Li3 中有一条 i18n 路线,如下所示:
Router::connect('/{:locale:[a-z]{2}/{:args}', [], [
'continue' => true,
'persist' => ['locale'],
]);
这样,当用户(或爬虫)使用语言前缀进入我的网站时,语言环境将用于生成网站上的每个链接。
出于 SEO 的目的,我需要在其他语言环境中生成 URL,例如:
GET /en/profile/john-doe
Canonical URL: https://www.example.com/en/profile/john-doe
Link hreflang for es: https://www.example.com/es/profile/john-doe
Link hreflang for pt: https://www.example.com/pt/profile/john-doe
我的货币方法是克隆当前请求,更改语言环境,从persist 数组中删除locale,并使用$request->to('url', ['absolute' => true]);。
但我无法摆脱语言环境。
关于如何解决这个问题的任何建议?
【问题讨论】:
-
我很确定您需要执行
'persist' => ['locale'],然后只需覆盖您在视图中传递给$this->url()的参数中的语言环境。您可能不需要像在帮助程序中那样重新传递所有参数。 -
再次感谢!是的,我已经在做
persist => ['locale']。这只是糟糕的复制/粘贴。
标签: php internationalization lithium php-5.5