<?php
require_once 'Zend/Translate/Adapter/Array.php';
/**
 * Goweb Sitemanager 5 Framework
 *
 * Action
 *
 * @version    5.0.24
 * @category   Goweb
 * @package    Goweb_Controller_Translate
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2010 (c) Goweb (http://www.goweb.pt)
 *
 */
class Goweb_Controller_Translate extends Zend_Translate_Adapter_Array{
    /**
     * Model a ser usado para guardar os translates
     *
     * @var Goweb_Db_Model
     */
    protected $_translateModel = null;

    /**
     * Generates the adapter
     *
     * @param  array               $data     Translation data
     * @param  string|Zend_Locale  $locale   OPTIONAL Locale/Language to set, identical with locale identifier,
     *                                       see Zend_Locale for more information
     * @param  array               $options  OPTIONAL Options to set
     */
    public function __construct($locale = null, array $options = array()){
        $this->_translateModel = goweb::getModelInstance('Sistema_Model_Action', 'db');
        $result = $this->_translateModel->fetchAll();
        $data = array();
        if ($result){
            foreach ($result as $item){
                $data[$item->nome] = $item->nome_traduzido;
            }
        } else {
            $data = array('' => '');
        }
        if (is_null($locale)){
            $session = Zend_Registry::get('session');
            $config = Zend_Registry::get('config');
            $locale = $config->languages->{$session->lang};
        }
        parent::__construct($data, $locale, $options);
    }
}