Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Translate.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Loader.php';
26 
30 #require_once 'Zend/Translate/Adapter.php';
31 
32 
43  const AN_ARRAY = 'Array';
44  const AN_CSV = 'Csv';
45  const AN_GETTEXT = 'Gettext';
46  const AN_INI = 'Ini';
47  const AN_QT = 'Qt';
48  const AN_TBX = 'Tbx';
49  const AN_TMX = 'Tmx';
50  const AN_XLIFF = 'Xliff';
51  const AN_XMLTM = 'XmlTm';
52 
53  const LOCALE_DIRECTORY = 'directory';
54  const LOCALE_FILENAME = 'filename';
55 
61  private $_adapter;
62 
71  public function __construct($options = array())
72  {
73  if ($options instanceof Zend_Config) {
74  $options = $options->toArray();
75  } else if (func_num_args() > 1) {
76  $args = func_get_args();
77  $options = array();
78  $options['adapter'] = array_shift($args);
79  if (!empty($args)) {
80  $options['content'] = array_shift($args);
81  }
82 
83  if (!empty($args)) {
84  $options['locale'] = array_shift($args);
85  }
86 
87  if (!empty($args)) {
88  $opt = array_shift($args);
89  $options = array_merge($opt, $options);
90  }
91  } else if (!is_array($options)) {
92  $options = array('adapter' => $options);
93  }
94 
95  $this->setAdapter($options);
96  }
97 
106  public function setAdapter($options = array())
107  {
108  if ($options instanceof Zend_Config) {
109  $options = $options->toArray();
110  } else if (func_num_args() > 1) {
111  $args = func_get_args();
112  $options = array();
113  $options['adapter'] = array_shift($args);
114  if (!empty($args)) {
115  $options['content'] = array_shift($args);
116  }
117 
118  if (!empty($args)) {
119  $options['locale'] = array_shift($args);
120  }
121 
122  if (!empty($args)) {
123  $opt = array_shift($args);
124  $options = array_merge($opt, $options);
125  }
126  } else if (!is_array($options)) {
127  $options = array('adapter' => $options);
128  }
129 
130  if (Zend_Loader::isReadable('Zend/Translate/Adapter/' . ucfirst($options['adapter']). '.php')) {
131  $options['adapter'] = 'Zend_Translate_Adapter_' . ucfirst($options['adapter']);
132  }
133 
134  if (!class_exists($options['adapter'])) {
135  Zend_Loader::loadClass($options['adapter']);
136  }
137 
138  if (array_key_exists('cache', $options)) {
140  }
141 
142  $adapter = $options['adapter'];
143  unset($options['adapter']);
144  $this->_adapter = new $adapter($options);
145  if (!$this->_adapter instanceof Zend_Translate_Adapter) {
146  #require_once 'Zend/Translate/Exception.php';
147  throw new Zend_Translate_Exception("Adapter " . $adapter . " does not extend Zend_Translate_Adapter");
148  }
149  }
150 
156  public function getAdapter()
157  {
158  return $this->_adapter;
159  }
160 
166  public static function getCache()
167  {
169  }
170 
177  public static function setCache(Zend_Cache_Core $cache)
178  {
180  }
181 
187  public static function hasCache()
188  {
190  }
191 
197  public static function removeCache()
198  {
200  }
201 
208  public static function clearCache($tag = null)
209  {
211  }
212 
216  public function __call($method, array $options)
217  {
218  if (method_exists($this->_adapter, $method)) {
219  return call_user_func_array(array($this->_adapter, $method), $options);
220  }
221  #require_once 'Zend/Translate/Exception.php';
222  throw new Zend_Translate_Exception("Unknown method '" . $method . "' called!");
223  }
224 }
__construct($options=array())
Definition: Translate.php:71
const AN_XMLTM
Definition: Translate.php:51
static loadClass($class, $dirs=null)
Definition: Loader.php:52
const LOCALE_FILENAME
Definition: Translate.php:54
setAdapter($options=array())
Definition: Translate.php:106
static setCache(Zend_Cache_Core $cache)
Definition: Translate.php:177
const AN_ARRAY
Definition: Translate.php:43
$adapter
Definition: webapi_user.php:16
static isReadable($filename)
Definition: Loader.php:162
static hasCache()
Definition: Translate.php:187
const LOCALE_DIRECTORY
Definition: Translate.php:53
__call($method, array $options)
Definition: Translate.php:216
static removeCache()
Definition: Translate.php:197
$method
Definition: info.phtml:13
static clearCache($tag=null)
Definition: Adapter.php:959
const AN_XLIFF
Definition: Translate.php:50
static setCache(Zend_Cache_Core $cache)
Definition: Adapter.php:923
const AN_GETTEXT
Definition: Translate.php:45
static clearCache($tag=null)
Definition: Translate.php:208
static getCache()
Definition: Translate.php:166