cakephp 通过 url 选择语言

发布于 2024-10-09 12:16:55 字数 877 浏览 2 评论 0原文

我想要实现的目标在这里描述 http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for -i18n-and-l10n-国际化和本地化/ 但我无法让它工作。

路由器配置如下所示:

Router::connect('/registered/:language/:controller/:action/*',
 array('prefix' => 'registered', 'registered' => true, 'layout'=> 'registered'),
 array('language' => '[a-z]{3}'));

但是当我尝试访问 www.example.com/registered/cze/packages 时,我得到:

错误:无法找到 CzeController。

作为作者,我使用 cake 1.3,而不是 1.2,这可能是问题所在,但是我需要更改什么才能使其正常工作?

编辑:

$this->Session->write('Config.language','cze');

此代码有效,并且在控制器中使用时会更改站点的语言,但我需要根据 URL 让它工作

what I am trying to achieve is described here http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for-i18n-and-l10n-internationalization-and-localization/
but I can not get it working.

The router configurations looks like this:

Router::connect('/registered/:language/:controller/:action/*',
 array('prefix' => 'registered', 'registered' => true, 'layout'=> 'registered'),
 array('language' => '[a-z]{3}'));

butw when I try to go to www.example.com/registered/cze/packages I get:

Error: CzeController could not be found.

I am using cake 1.3, not 1.2 as the author, that may be the problem, but what do I need to change in order for this to work?

Edit:

$this->Session->write('Config.language','cze');

This code works and when used in the controller changes the language of the site, but I need to get it working according to the URL

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷了相思 2024-10-16 12:16:55

URL www.example.com/registered/cze/packages 与路由 /registered/:language/:controller/:action/* 不匹配,因为 >:action 段为空。因此,URL 会进入标准路由,其中​​ registered 被识别为前缀,cze 被识别为控制器。

您还需要创建一个“更短”的 /registered/:language/:controller 路由来捕获“缩写”URL。

The URL www.example.com/registered/cze/packages does not match the route /registered/:language/:controller/:action/*, since the :action segment is empty. Therefore, the URL falls through to the standard route, where registered is recognized as the prefix and cze as the controller.

You'll need to create a "shorter" /registered/:language/:controller route as well to catch "abbreviated" URLs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文