Zend Routes translate URL's

ⅰ亾dé卋堺 提交于 2019-12-04 15:16:21

According to this post: http://www.z-f.fr/forum/viewtopic.php?id=5138

The solution is to add '@locale' => $lang to the params.

$this->url(array('lang'=>'it','@locale'=>'it'))

It works very well for me.

I've been looking into translating the URL with Zend_Translate and I came across this sites' plugin that attempts to auto-translate URL segments (module/controller/action).

http://blog.helmich.cz/305-howto-simple-multilingual-routes-in-zend-framework/

The nice thing is that it's a modified custom router class that can function similar to Zend_Router so it's relatively familiar off the bat.

$pages = new MyApp_Controller_Router_Route(
    ':locale/:@controller/:@action/*',
    array(
        'controller' =>; 'index',
                'action'     => 'index',
                'locale'     => 'cs'
            )
);

$router->addRoute('pages',$pages);

The thing you'll need is to have a language ID in your URL (called :locale in the above example) so your Zend_Translate can set the proper language.

www.example.com/en/calendar/2012-06-22/
www.example.com/fr/calendrier/2012-06-22/
www.example.com/de/kalender/2012-06-22/
www.example.com/it/calendario/2012-06-22/

I've only slightly played around with this concept but I recall that it had promise. You'll have to get more familiar with Zend_Translate: http://framework.zend.com/manual/en/zend.translate.html

I hope that helps!

Cheers!

You could re-route all calls of calendar to kalendar. There are two possibilites, either you do it with Zend (preferable) or you change your webserver configuration to rewrite calls to calendar with a HTTP 302 (ugly).

You should however consult the official Zend Documentation, which is pretty good

tasmaniski

You have to setup custom routes, this is my way:

in folder application/configs/ create file named "routes.ini"

Put in file your route:

;index-homepage, parameter date isn't required
;"index" is key of your route
routes.index.route = "kalendar/:date" 
routes.index.defaults.controller = calendar
routes.index.defaults.action = show
routes.index.defaults.date =

So in your bootstrap.php define that config file:

protected function _initRoute() {
    $router = Zend_Controller_Front::getInstance()->getRouter();
    $router->addDefaultRoutes();

    $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini');
    $router->addConfig($config, 'routes');
}

And that's it, you can call URL

www.website.com/kalendar

and

www.website.com/kalendar/2012-1-1

See answers in this question for details: Simple rewrites in Zend Framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!