Zend Framework 和切换视图脚本路径

发布于 2024-08-06 03:09:18 字数 280 浏览 4 评论 0原文

我有一个问题。基本上,根据用户是否访问我们网站上的 /es 或 /br 或 /cn 等,我们有不同的语言模板文件。到目前为止,我们使用自定义模板引擎来完成这项工作,但正在切换到 ZF。如果语言变量是 cn,我似乎无法弄清楚如何让 ZF 在 cn/about-us 中查找视图脚本。

我不能(不想)为此使用 Zend_Translate,因为我们有太多翻译的模板文件,并且使用 Zend_Translate 来处理无数包含中文/韩文/日文多段落的不同文件是不可行的,忘记了一秒钟我不会说这些语言。

有人可以帮助我吗?

I have a problem. Basically, depending on whether a user goes to /es or /br or /cn etc on our website, we have different language template files. So far, we were using a custom templating engine to make this work, but are making a switch over to ZF. I can't seem to figure out how to get ZF to look for a view script in say cn/about-us if the language varuable is cn.

I can't (don't want to) use Zend_Translate for this because we have way too many translated template files and it's just not feasible using Zend_Translate for bazillion different files with multi-paragraphs of Chinese/Korean/Japanese, forgetting for a second that I don't speak those languages.

Can anybody help me?

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

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

发布评论

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

评论(1

梦过后 2024-08-13 03:09:18

您可以编写一个控制器插件并使用它的routeStartup()方法来更改Zend_View设置(视图脚本所在的路径)并在路由开始之前更改请求uri。

class My_Controller_Plugin_LanguageSwitcher extends Zend_Controller_Plugin_Abstract
{
    public function routeStartup(Zend_Controller_Request_Abstract $request)
    {
        // examine the $_SERVER['REQUEST_URI'] and look for your language identifier
        // fetch the View and set appropriate view scripts path using setScriptPath() method
        // strip the language identifier from your REQUEST_URI
        // change the request uri using $request->setRequestUri('your-new-uri-without-the-language-  identifier');
    }
}

You can write a controller plugin and use it's routeStartup() method to alter Zend_View settings (path to where your view scripts are located) and change the request uri before routing starts.

class My_Controller_Plugin_LanguageSwitcher extends Zend_Controller_Plugin_Abstract
{
    public function routeStartup(Zend_Controller_Request_Abstract $request)
    {
        // examine the $_SERVER['REQUEST_URI'] and look for your language identifier
        // fetch the View and set appropriate view scripts path using setScriptPath() method
        // strip the language identifier from your REQUEST_URI
        // change the request uri using $request->setRequestUri('your-new-uri-without-the-language-  identifier');
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文