title: Zend_Translate Strategy for a huge grown web site
body: <p>since I'm thinking in a good way to handle translation did part of a implementation and going toward a concept that still don't know if it's good and I would like to share it and get the pros and cons of it with someone that think it's a good point to explore.</p>
  
  <p>The architecture is meant to work in a componentized site with translations comming from  Actions, Forms, Views, View_Helpers and even Action_Helpers.</p>
  
  <p>The ideis is simple: </p>
  
  <p>Zend_Translate will the got from registry in every component and will receive <code>__FILE__</code> as parameter. Since it was initialized with 'clear' on bootstrap it will be possible to load just the array file that correspont to this calling compoment. When comes to the missing translations they will be logged to a database (to avoid log duplicates) and/or be added to the corresponding array file in the remaining untranslated languages (as well as have the array file created) with a null value where it's is not set yet.</p>
  
  <p>My guess is that using cache and specializing Translate i can ignore the translations that are set with null (by the addition made before) without log it again (displayin just the key) it will overhead a little bit the firt call for a large untraslated page and then gain performance later as well as maintainability and work ability with the automation of the translation process that would like to supply for the user.</p>
  
  <p>But after that I was figuring out that I could build a array with the missing translations from every component to be save at the request end, and that is my question.</p>
  
  <p>Had you folks had some experience with this that could be helpful to determine what's the best strategy?</p>
  
  <p>bootstrap</p>
  
  <pre><code>protected function _initLocale() {
      $translateSession = new Zend_Session_Namespace('translate');
      $locale = isset($translateSession-&gt;locale) ? $translateSession-&gt;locale : 'auto';
      try {
          $zendLocale  = new Zend_Locale($locale);
      } catch (Zend_Locale_Exception $e) {
          $zendLocale = new Zend_Locale('en_US');
      }   
      Zend_Registry::set('Zend_Locale', $zendLocale);
      $translate = new Engine_Translate('customarray', array('clear'));
      $logger = Engine_Logger::getLogger();
      $translate-&gt;setOptions( array('log2db' =&gt; $logger ,'log' =&gt; $logger,  'logPriority' =&gt; Zend_Log::ALERT, 'logUntranslated' =&gt; true));
      Zend_Registry::set('Zend_Translate', $translate);
  }
  </code></pre>
  
  <p>simple library </p>
  
  <pre><code>function getAvailableTranslationLanguages() {
      return array("pt_BR"=&gt;"Português","en_US"=&gt;"Inglês");
  }
  
  function setTranslationLanguage($code) {
      $translateSession = new Zend_Session_Namespace('translate');
      $translateSession-&gt;locale = $code;
  }
  
  function getTranslator($file) {
      $relative = str_replace(APPLICATION_PATH, '', $file);
      $code = Zend_Registry::get('Zend_Locale');
      $path = APPLICATION_PATH . '\\lang\\' . $code . $relative;
      $translator = Zend_Registry::get('Zend_Translate');
      try {
          $translator-&gt;addTranslation($path, $code);
      } catch (Exception $e) {
          createTranslationFile($path);
      }
      return $translator;
  }
  
  function createTranslationFile($path) {
      if(!file_exists(dirname($path)))
          mkdir(dirname($path), 0777, true);
      $file = fopen($path, 'w');
      if($file) {
          $stringData = "&lt;?php\n  return array(\n );";
          fwrite($file, $stringData);
          fclose($file);
      } else {
          $logger = Engine_Logger::getLogger();
          $logger-&gt;info(Engine_Logger::get_string('ERRO ao abrir arquivo de tradução: ' . $path));
      }   
  }
  </code></pre>
  
  <p>The use </p>
  
  <pre><code>class App_Views_Helpers_Loginbox extends Zend_View_Helper_Abstract
  {
      public function loginbox() {
          $translate = getTranslator(__FILE__);
  </code></pre>
  
  <p>Translation resources</p>
  
  <p><img src="https://i.stack.imgur.com/tUt7Z.png" alt="enter image description here"></p>