title: Zend Framework Multilanguage
body: <p>I'm trying to make my Zend Framework website in multiple languages, I want it to be easy to increment the number of languages in my website.</p>
  
  <p>I tried following this tutorial, but I'm having some problems:
  <a href="http://blog.hackix.com/series/working-with-zend_translate-and-poedit/" rel="nofollow">http://blog.hackix.com/series/working-with-zend_translate-and-poedit/</a></p>
  
  <p>I got my language files nl_BE and en_US, changed the content in my views by e.g. <code>echo $this-&gt;translate("Restricted section");</code></p>
  
  <p>First, I was able to change the default language by changing it in the Bootstrap.php, but after a couple of tries to make it work without the Bootstrap.php and changing some code, even that doesn't work anymore.</p>
  
  <p>I made a little form, with two images, a Belgian flag and a Brittish flag, if I click the Belgian flag I want to change the language to nl_BE, if I click the Brittish flag, I want to change the language to en_US.</p>
  
  <p>This is my form:</p>
  
  <pre><code>&lt;form action="" method="post"&gt;
       &lt;input type="image" src="images/belgium.png" value="nl_BE" name="lang" /&gt;
       &lt;input type="image" src="images/brittain.png" value="en_US" name="lang"/&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>This is my Bootstrap.php file, according to the tutorial I used:</p>
  
  <pre><code>&lt;?php
  
  class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
  
  protected function _initTranslate() 
      {
  
      Zend_Loader::loadClass('Zend_Translate');
      Zend_Loader::loadClass('Zend_Registry');
  
  
      // Get current registry
      $registry = Zend_Registry::getInstance();
      /**
       * Set application wide source Locale
       * This is usually your source string language;
       * i.e. $this-&gt;translate('Hi I am an English String');
       */
      $locale = new Zend_Locale('en_US');    
      Zend_Registry::set('Zend_Locale', $locale);
  
      $session = new Zend_Session_Namespace('session');
      //$langLocale = isset($session-&gt;lang) ? $session-&gt;lang : $locale;
      $langLocale = $locale;
  
      /**
       * Set up and load the translations (all of them!)
       * resources.translate.options.disableNotices = true
       * resources.translate.options.logUntranslated = true
       */
      $translate = new Zend_Translate('gettext', 
          APPLICATION_PATH . DIRECTORY_SEPARATOR .'languages', 'auto',
          array(
          'disableNotices' =&gt; true,    // This is a very good idea!
          'logUntranslated' =&gt; false,  // Change this if you debug
          )
      );
      /**
       * Both of these registry keys are magical and makes
       * ZF 1.7+ do automagical things.
       */
      $registry-&gt;set('Zend_Locale', $locale);
      $registry-&gt;set('Zend_Translate', $translate);
      return $registry;
   }
  }
  </code></pre>
  
  <p>This is my LangController.php, the Zend_Controller_Plugin_Abstract to handle the change of language, this file is placed in library/App/Controller/Plugin.</p>
  
  <pre><code>    &lt;?php
  class App_Controller_Plugin_LangSelector extends Zend_Controller_Plugin_Abstract
   {
      public function preDispatch(Zend_Controller_Request_Abstract $request)
      {
      $registry = Zend_Registry::getInstance();
      // Get our translate object from registry.
      $translate = $registry-&gt;get('Zend_Translate');
      $currLocale = $translate-&gt;getLocale();
      // Create Session block and save the locale
      $session = new Zend_Session_Namespace('session');
  
      $lang = $request-&gt;getParam('lang','');
      // Register all your "approved" locales below.
      switch($lang) {
          case "nl_BE": 
              $langLocale = 'nl_BE';
              break;   
          case "en_US": 
              $langLocale = 'en_US'; 
              break;
          default:
              /**
               * Get a previously set locale from session or set
               * the current application wide locale (set in 
               * Bootstrap)if not.
               */
              $langLocale = isset($session-&gt;lang) ? $session-&gt;lang : $currLocale;
      }
  
      $newLocale = new Zend_Locale();
      $newLocale-&gt;setLocale($langLocale);
      $registry-&gt;set('Zend_Locale', $newLocale);
  
      $translate-&gt;setLocale($langLocale);
      $session-&gt;lang = $langLocale;
  
      // Save the modified translate back to registry
      $registry-&gt;set('Zend_Translate', $translate);
   }
  }
  </code></pre>
  
  <p>Can someone please help me, tell me what I'm doing wrong? Because I've been trying for hours now and I think I'm really stuck.</p>