1
votes

I have built a multilingual web site. Language can be switched by clicking the flags on the site. When clicking any of it, the request is submitted to a controller with following code:

<?php

class LanguageSwitchController extends Zend_Controller_Action
{
    protected $_redirector = null;
    public function init(){
        $this->_helper->layout->disableLayout;
        $this->_helper->viewRenderer->setNoRender();

        $this->_redirector = $this->_helper->getHelper('Redirector');
/*      $this->_redirector->setGotoUrl($this->getInvokeArg('referer'));
*/
    }
    public function switchAction(){
        $session = new Zend_Session_Namespace('language');
        $session->language = $this->_getParam('lang');

        $this->_redirector->gotoUrl($_SERVER['HTTP_REFERER']);
    }
}

All the parameters related to Zend_Session, Zend_Translate and Zend_Locale are defined in Bootstripe file. Basically everything works fine. I am using Array adapter. All the translations are stored in 3 php files (ro, ru, en) and depending on selected language the page is displayed in respective language. The problem is that each page doesn't have a unique URL for each language. For example, if the user being on page http://mysite.com/mycontroller/myaction (lets assume that the page is displayed in English, because it is the default language of the users browser - the site detects automatically the default language of the browser) and will decide to turn it to Russian by clicking respecive flag, the site will be displayed in Russian, but the URL will remain the same: http://mysite.com/mycontroller/myaction. In such way I cannot index it appropriately by Google, for example. Without having unique URL for each page in each language, I will be able to index it only for one language (default one I believe). Is there any possibility to adjust somehow the project or do I have to completely change the structure of the site? Generally speaking, what is the most efficient way to arganize the structure of the project based on Zend Framework, when the site is translated in a few languages? Thank You.

1
Yes, there is a way, check out custom routes. And that logic from controller you can move to bootstrap, so you will have only one request. Just ask if(isset($_GET['lang'])){...} and that rest code from your bootstrap function.tasmaniski

1 Answers

1
votes

How about using custom routes? For example, define a route for English by:

routes.english.route = "en/:controller/:action"
routes.english.defaults.lang = en