00001 <?php 00024 require_once 'Zend/Locale.php'; 00025 00027 require_once 'Zend/Translate/Adapter.php'; 00028 00029 00036 class Zend_Translate_Adapter_Csv extends Zend_Translate_Adapter 00037 { 00038 private $_data = array(); 00039 00048 public function __construct($data, $locale = null, array $options = array()) 00049 { 00050 $this->_options['delimiter'] = ";"; 00051 $this->_options['length'] = 0; 00052 $this->_options['enclosure'] = '"'; 00053 parent::__construct($data, $locale, $options); 00054 } 00055 00065 protected function _loadTranslationData($filename, $locale, array $options = array()) 00066 { 00067 $this->_data = array(); 00068 $options = $options + $this->_options; 00069 $this->_file = @fopen($filename, 'rb'); 00070 if (!$this->_file) { 00071 require_once 'Zend/Translate/Exception.php'; 00072 throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.'); 00073 } 00074 00075 while(($data = fgetcsv($this->_file, $options['length'], $options['delimiter'], $options['enclosure'])) !== false) { 00076 if (substr($data[0], 0, 1) === '#') { 00077 continue; 00078 } 00079 00080 if (!isset($data[1])) { 00081 continue; 00082 } 00083 00084 if (count($data) == 2) { 00085 $this->_data[$locale][$data[0]] = $data[1]; 00086 } else { 00087 $singular = array_shift($data); 00088 $this->_data[$locale][$singular] = $data; 00089 } 00090 } 00091 00092 return $this->_data; 00093 } 00094 00100 public function toString() 00101 { 00102 return "Csv"; 00103 } 00104 }