Adapter.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Translate
  17. * @subpackage Zend_Translate_Adapter
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Locale
  24. */
  25. require_once 'Zend/Locale.php';
  26. /**
  27. * @see Zend_Translate_Plural
  28. */
  29. require_once 'Zend/Translate/Plural.php';
  30. /**
  31. * Basic adapter class for each translation source adapter
  32. *
  33. * @category Zend
  34. * @package Zend_Translate
  35. * @subpackage Zend_Translate_Adapter
  36. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. abstract class Zend_Translate_Adapter {
  40. /**
  41. * Shows if locale detection is in automatic level
  42. * @var boolean
  43. */
  44. private $_automatic = true;
  45. /**
  46. * Internal cache for all adapters
  47. * @var Zend_Cache_Core
  48. */
  49. protected static $_cache = null;
  50. /**
  51. * Scans for the locale within the name of the directory
  52. * @constant integer
  53. */
  54. const LOCALE_DIRECTORY = 'directory';
  55. /**
  56. * Scans for the locale within the name of the file
  57. * @constant integer
  58. */
  59. const LOCALE_FILENAME = 'filename';
  60. /**
  61. * Array with all options, each adapter can have own additional options
  62. * 'clear' => clears already loaded data when adding new files
  63. * 'scan' => searches for translation files using the LOCALE constants
  64. * 'locale' => the actual set locale to use
  65. * @var array
  66. */
  67. protected $_options = array(
  68. 'clear' => false,
  69. 'disableNotices' => false,
  70. 'ignore' => '.',
  71. 'locale' => 'auto',
  72. 'log' => null,
  73. 'logMessage' => "Untranslated message within '%locale%': %message%",
  74. 'logUntranslated' => false,
  75. 'scan' => null
  76. );
  77. /**
  78. * Translation table
  79. * @var array
  80. */
  81. protected $_translate = array();
  82. /**
  83. * Generates the adapter
  84. *
  85. * @param string|array $data Translation data or filename for this adapter
  86. * @param string|Zend_Locale $locale (optional) Locale/Language to set, identical with Locale
  87. * identifiers see Zend_Locale for more information
  88. * @param array $options (optional) Options for the adaptor
  89. * @throws Zend_Translate_Exception
  90. * @return void
  91. */
  92. public function __construct($data, $locale = null, array $options = array())
  93. {
  94. if (isset(self::$_cache)) {
  95. $id = 'Zend_Translate_' . $this->toString() . '_Options';
  96. $result = self::$_cache->load($id);
  97. if ($result) {
  98. $this->_options = unserialize($result);
  99. }
  100. }
  101. if (($locale === "auto") or ($locale === null)) {
  102. $this->_automatic = true;
  103. } else {
  104. $this->_automatic = false;
  105. }
  106. $this->setOptions($options);
  107. $this->addTranslation($data, $locale, $options);
  108. if ($this->getLocale() !== (string) $locale) {
  109. $this->setLocale($locale);
  110. }
  111. }
  112. /**
  113. * Add translation data
  114. *
  115. * It may be a new language or additional data for existing language
  116. * If $clear parameter is true, then translation data for specified
  117. * language is replaced and added otherwise
  118. *
  119. * @param array|string $data Translation data
  120. * @param string|Zend_Locale $locale (optional) Locale/Language to add data for, identical
  121. * with locale identifier, see Zend_Locale for more information
  122. * @param array $options (optional) Option for this Adapter
  123. * @throws Zend_Translate_Exception
  124. * @return Zend_Translate_Adapter Provides fluent interface
  125. */
  126. public function addTranslation($data, $locale = null, array $options = array())
  127. {
  128. $originate = (string) $locale;
  129. if (array_key_exists('locale', $options)) {
  130. if ($locale == null) {
  131. $locale = $options['locale'];
  132. }
  133. unset($options['locale']);
  134. }
  135. if ((array_key_exists('log', $options)) && !($options['log'] instanceof Zend_Log)) {
  136. require_once 'Zend/Translate/Exception.php';
  137. throw new Zend_Translate_Exception('Instance of Zend_Log expected for option log');
  138. }
  139. try {
  140. $locale = Zend_Locale::findLocale($locale);
  141. } catch (Zend_Locale_Exception $e) {
  142. require_once 'Zend/Translate/Exception.php';
  143. throw new Zend_Translate_Exception("The given Language '{$locale}' does not exist");
  144. }
  145. $options = $options + $this->_options;
  146. if (is_string($data) and is_dir($data)) {
  147. $data = realpath($data);
  148. $prev = '';
  149. foreach (new RecursiveIteratorIterator(
  150. new RecursiveDirectoryIterator($data, RecursiveDirectoryIterator::KEY_AS_PATHNAME),
  151. RecursiveIteratorIterator::SELF_FIRST) as $directory => $info) {
  152. $file = $info->getFilename();
  153. if (strpos($directory, DIRECTORY_SEPARATOR . $options['ignore']) !== false) {
  154. // ignore files matching first characters from option 'ignore' and all files below
  155. continue;
  156. }
  157. if ($info->isDir()) {
  158. // pathname as locale
  159. if (($options['scan'] === self::LOCALE_DIRECTORY) and (Zend_Locale::isLocale($file, true, false))) {
  160. $locale = $file;
  161. $prev = (string) $locale;
  162. }
  163. } else if ($info->isFile()) {
  164. // filename as locale
  165. if ($options['scan'] === self::LOCALE_FILENAME) {
  166. $filename = explode('.', $file);
  167. array_pop($filename);
  168. $filename = implode('.', $filename);
  169. if (Zend_Locale::isLocale((string) $filename, true, false)) {
  170. $locale = (string) $filename;
  171. } else {
  172. $parts = explode('.', $file);
  173. $parts2 = array();
  174. foreach($parts as $token) {
  175. $parts2 += explode('_', $token);
  176. }
  177. $parts = array_merge($parts, $parts2);
  178. $parts2 = array();
  179. foreach($parts as $token) {
  180. $parts2 += explode('-', $token);
  181. }
  182. $parts = array_merge($parts, $parts2);
  183. $parts = array_unique($parts);
  184. $prev = '';
  185. foreach($parts as $token) {
  186. if (Zend_Locale::isLocale($token, true, false)) {
  187. if (strlen($prev) <= strlen($token)) {
  188. $locale = $token;
  189. $prev = $token;
  190. }
  191. }
  192. }
  193. }
  194. }
  195. try {
  196. $this->_addTranslationData($info->getPathname(), (string) $locale, $options);
  197. } catch (Zend_Translate_Exception $e) {
  198. // ignore failed sources while scanning
  199. }
  200. }
  201. }
  202. } else {
  203. $this->_addTranslationData($data, (string) $locale, $options);
  204. }
  205. if ((isset($this->_translate[$originate]) === true) and (count($this->_translate[$originate]) > 0)) {
  206. $this->setLocale($originate);
  207. }
  208. return $this;
  209. }
  210. /**
  211. * Sets new adapter options
  212. *
  213. * @param array $options Adapter options
  214. * @throws Zend_Translate_Exception
  215. * @return Zend_Translate_Adapter Provides fluent interface
  216. */
  217. public function setOptions(array $options = array())
  218. {
  219. $change = false;
  220. $locale = null;
  221. foreach ($options as $key => $option) {
  222. if ($key == 'locale') {
  223. $locale = $option;
  224. } else if ((isset($this->_options[$key]) and ($this->_options[$key] != $option)) or
  225. !isset($this->_options[$key])) {
  226. if (($key == 'log') && !($option instanceof Zend_Log)) {
  227. require_once 'Zend/Translate/Exception.php';
  228. throw new Zend_Translate_Exception('Instance of Zend_Log expected for option log');
  229. }
  230. $this->_options[$key] = $option;
  231. $change = true;
  232. }
  233. }
  234. if ($locale !== null) {
  235. $this->setLocale($locale);
  236. }
  237. if (isset(self::$_cache) and ($change == true)) {
  238. $id = 'Zend_Translate_' . $this->toString() . '_Options';
  239. self::$_cache->save( serialize($this->_options), $id, array('Zend_Translate'));
  240. }
  241. return $this;
  242. }
  243. /**
  244. * Returns the adapters name and it's options
  245. *
  246. * @param string|null $optionKey String returns this option
  247. * null returns all options
  248. * @return integer|string|array|null
  249. */
  250. public function getOptions($optionKey = null)
  251. {
  252. if ($optionKey === null) {
  253. return $this->_options;
  254. }
  255. if (isset($this->_options[$optionKey]) === true) {
  256. return $this->_options[$optionKey];
  257. }
  258. return null;
  259. }
  260. /**
  261. * Gets locale
  262. *
  263. * @return Zend_Locale|string|null
  264. */
  265. public function getLocale()
  266. {
  267. return $this->_options['locale'];
  268. }
  269. /**
  270. * Sets locale
  271. *
  272. * @param string|Zend_Locale $locale Locale to set
  273. * @throws Zend_Translate_Exception
  274. * @return Zend_Translate_Adapter Provides fluent interface
  275. */
  276. public function setLocale($locale)
  277. {
  278. if (($locale === "auto") or ($locale === null)) {
  279. $this->_automatic = true;
  280. } else {
  281. $this->_automatic = false;
  282. }
  283. try {
  284. $locale = Zend_Locale::findLocale($locale);
  285. } catch (Zend_Locale_Exception $e) {
  286. require_once 'Zend/Translate/Exception.php';
  287. throw new Zend_Translate_Exception("The given Language ({$locale}) does not exist");
  288. }
  289. if (!isset($this->_translate[$locale])) {
  290. $temp = explode('_', $locale);
  291. if (!isset($this->_translate[$temp[0]]) and !isset($this->_translate[$locale])) {
  292. if (!$this->_options['disableNotices']) {
  293. if ($this->_options['log']) {
  294. $this->_options['log']->notice("The language '{$locale}' has to be added before it can be used.");
  295. } else {
  296. trigger_error("The language '{$locale}' has to be added before it can be used.", E_USER_NOTICE);
  297. }
  298. }
  299. }
  300. $locale = $temp[0];
  301. }
  302. if (empty($this->_translate[$locale])) {
  303. if (!$this->_options['disableNotices']) {
  304. if ($this->_options['log']) {
  305. $this->_options['log']->notice("No translation for the language '{$locale}' available.");
  306. } else {
  307. trigger_error("No translation for the language '{$locale}' available.", E_USER_NOTICE);
  308. }
  309. }
  310. }
  311. if ($this->_options['locale'] != $locale) {
  312. $this->_options['locale'] = $locale;
  313. if (isset(self::$_cache)) {
  314. $id = 'Zend_Translate_' . $this->toString() . '_Options';
  315. self::$_cache->save( serialize($this->_options), $id, array('Zend_Translate'));
  316. }
  317. }
  318. return $this;
  319. }
  320. /**
  321. * Returns the available languages from this adapter
  322. *
  323. * @return array
  324. */
  325. public function getList()
  326. {
  327. $list = array_keys($this->_translate);
  328. $result = null;
  329. foreach($list as $value) {
  330. if (!empty($this->_translate[$value])) {
  331. $result[$value] = $value;
  332. }
  333. }
  334. return $result;
  335. }
  336. /**
  337. * Returns all available message ids from this adapter
  338. * If no locale is given, the actual language will be used
  339. *
  340. * @param string|Zend_Locale $locale (optional) Language to return the message ids from
  341. * @return array
  342. */
  343. public function getMessageIds($locale = null)
  344. {
  345. if (empty($locale) or !$this->isAvailable($locale)) {
  346. $locale = $this->_options['locale'];
  347. }
  348. return array_keys($this->_translate[(string) $locale]);
  349. }
  350. /**
  351. * Returns all available translations from this adapter
  352. * If no locale is given, the actual language will be used
  353. * If 'all' is given the complete translation dictionary will be returned
  354. *
  355. * @param string|Zend_Locale $locale (optional) Language to return the messages from
  356. * @return array
  357. */
  358. public function getMessages($locale = null)
  359. {
  360. if ($locale === 'all') {
  361. return $this->_translate;
  362. }
  363. if ((empty($locale) === true) or ($this->isAvailable($locale) === false)) {
  364. $locale = $this->_options['locale'];
  365. }
  366. return $this->_translate[(string) $locale];
  367. }
  368. /**
  369. * Is the wished language available ?
  370. *
  371. * @see Zend_Locale
  372. * @param string|Zend_Locale $locale Language to search for, identical with locale identifier,
  373. * @see Zend_Locale for more information
  374. * @return boolean
  375. */
  376. public function isAvailable($locale)
  377. {
  378. $return = isset($this->_translate[(string) $locale]);
  379. return $return;
  380. }
  381. /**
  382. * Load translation data
  383. *
  384. * @param mixed $data
  385. * @param string|Zend_Locale $locale
  386. * @param array $options (optional)
  387. * @return array
  388. */
  389. abstract protected function _loadTranslationData($data, $locale, array $options = array());
  390. /**
  391. * Internal function for adding translation data
  392. *
  393. * It may be a new language or additional data for existing language
  394. * If $clear parameter is true, then translation data for specified
  395. * language is replaced and added otherwise
  396. *
  397. * @see Zend_Locale
  398. * @param array|string $data Translation data
  399. * @param string|Zend_Locale $locale Locale/Language to add data for, identical with locale identifier,
  400. * @see Zend_Locale for more information
  401. * @param array $options (optional) Option for this Adapter
  402. * @throws Zend_Translate_Exception
  403. * @return Zend_Translate_Adapter Provides fluent interface
  404. */
  405. private function _addTranslationData($data, $locale, array $options = array())
  406. {
  407. try {
  408. $locale = Zend_Locale::findLocale($locale);
  409. } catch (Zend_Locale_Exception $e) {
  410. require_once 'Zend/Translate/Exception.php';
  411. throw new Zend_Translate_Exception("The given Language '{$locale}' does not exist");
  412. }
  413. if ($options['clear'] || !isset($this->_translate[$locale])) {
  414. $this->_translate[$locale] = array();
  415. }
  416. $read = true;
  417. if (isset(self::$_cache)) {
  418. $id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
  419. $result = self::$_cache->load($id);
  420. if ($result) {
  421. $temp = unserialize($result);
  422. $read = false;
  423. }
  424. }
  425. if ($read) {
  426. $temp = $this->_loadTranslationData($data, $locale, $options);
  427. }
  428. if (empty($temp)) {
  429. $temp = array();
  430. }
  431. $keys = array_keys($temp);
  432. foreach($keys as $key) {
  433. if (!isset($this->_translate[$key])) {
  434. $this->_translate[$key] = array();
  435. }
  436. if (array_key_exists($key, $temp) && is_array($temp[$key])) {
  437. $this->_translate[$key] = $temp[$key] + $this->_translate[$key];
  438. }
  439. }
  440. if ($this->_automatic === true) {
  441. $find = new Zend_Locale($locale);
  442. $browser = $find->getEnvironment() + $find->getBrowser();
  443. arsort($browser);
  444. foreach($browser as $language => $quality) {
  445. if (isset($this->_translate[$language])) {
  446. $this->_options['locale'] = $language;
  447. break;
  448. }
  449. }
  450. }
  451. if (($read) and (isset(self::$_cache))) {
  452. $id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
  453. self::$_cache->save( serialize($temp), $id, array('Zend_Translate'));
  454. }
  455. return $this;
  456. }
  457. /**
  458. * Translates the given string
  459. * returns the translation
  460. *
  461. * @see Zend_Locale
  462. * @param string|array $messageId Translation string, or Array for plural translations
  463. * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with
  464. * locale identifier, @see Zend_Locale for more information
  465. * @return string
  466. */
  467. public function translate($messageId, $locale = null)
  468. {
  469. if ($locale === null) {
  470. $locale = $this->_options['locale'];
  471. }
  472. $plural = null;
  473. if (is_array($messageId)) {
  474. if (count($messageId) > 2) {
  475. $number = array_pop($messageId);
  476. if (!is_numeric($number)) {
  477. $plocale = $number;
  478. $number = array_pop($messageId);
  479. } else {
  480. $plocale = 'en';
  481. }
  482. $plural = $messageId;
  483. $messageId = $messageId[0];
  484. } else {
  485. $messageId = $messageId[0];
  486. }
  487. }
  488. if (!Zend_Locale::isLocale($locale, true, false)) {
  489. if (!Zend_Locale::isLocale($locale, false, false)) {
  490. // language does not exist, return original string
  491. $this->_log($messageId, $locale);
  492. if ($plural === null) {
  493. return $messageId;
  494. }
  495. $rule = Zend_Translate_Plural::getPlural($number, $plocale);
  496. if (!isset($plural[$rule])) {
  497. $rule = 0;
  498. }
  499. return $plural[$rule];
  500. }
  501. $locale = new Zend_Locale($locale);
  502. }
  503. $locale = (string) $locale;
  504. if (isset($this->_translate[$locale][$messageId])) {
  505. // return original translation
  506. if ($plural === null) {
  507. return $this->_translate[$locale][$messageId];
  508. }
  509. $rule = Zend_Translate_Plural::getPlural($number, $locale);
  510. if (isset($this->_translate[$locale][$plural[0]][$rule])) {
  511. return $this->_translate[$locale][$plural[0]][$rule];
  512. }
  513. } else if (strlen($locale) != 2) {
  514. // faster than creating a new locale and separate the leading part
  515. $locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
  516. if (isset($this->_translate[$locale][$messageId])) {
  517. // return regionless translation (en_US -> en)
  518. if ($plural === null) {
  519. return $this->_translate[$locale][$messageId];
  520. }
  521. $rule = Zend_Translate_Plural::getPlural($number, $locale);
  522. if (isset($this->_translate[$locale][$plural[0]][$rule])) {
  523. return $this->_translate[$locale][$plural[0]][$rule];
  524. }
  525. }
  526. }
  527. $this->_log($messageId, $locale);
  528. if ($plural === null) {
  529. return $messageId;
  530. }
  531. $rule = Zend_Translate_Plural::getPlural($number, $plocale);
  532. if (!isset($plural[$rule])) {
  533. $rule = 0;
  534. }
  535. return $plural[$rule];
  536. }
  537. /**
  538. * Translates the given string using plural notations
  539. * Returns the translated string
  540. *
  541. * @see Zend_Locale
  542. * @param string $singular Singular translation string
  543. * @param string $plural Plural translation string
  544. * @param integer $number Number for detecting the correct plural
  545. * @param string|Zend_Locale $locale (Optional) Locale/Language to use, identical with
  546. * locale identifier, @see Zend_Locale for more information
  547. * @return string
  548. */
  549. public function plural($singular, $plural, $number, $locale = null)
  550. {
  551. return $this->translate(array($singular, $plural, $number), $locale);
  552. }
  553. /**
  554. * Logs a message when the log option is set
  555. *
  556. * @param string $message Message to log
  557. * @param String $locale Locale to log
  558. */
  559. protected function _log($message, $locale) {
  560. if ($this->_options['logUntranslated']) {
  561. $message = str_replace('%message%', $message, $this->_options['logMessage']);
  562. $message = str_replace('%locale%', $locale, $message);
  563. if ($this->_options['log']) {
  564. $this->_options['log']->notice($message);
  565. } else {
  566. trigger_error($message, E_USER_NOTICE);
  567. }
  568. }
  569. }
  570. /**
  571. * Translates the given string
  572. * returns the translation
  573. *
  574. * @param string $messageId Translation string
  575. * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale
  576. * identifier, @see Zend_Locale for more information
  577. * @return string
  578. */
  579. public function _($messageId, $locale = null)
  580. {
  581. return $this->translate($messageId, $locale);
  582. }
  583. /**
  584. * Checks if a string is translated within the source or not
  585. * returns boolean
  586. *
  587. * @param string $messageId Translation string
  588. * @param boolean $original (optional) Allow translation only for original language
  589. * when true, a translation for 'en_US' would give false when it can
  590. * be translated with 'en' only
  591. * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale identifier,
  592. * see Zend_Locale for more information
  593. * @return boolean
  594. */
  595. public function isTranslated($messageId, $original = false, $locale = null)
  596. {
  597. if (($original !== false) and ($original !== true)) {
  598. $locale = $original;
  599. $original = false;
  600. }
  601. if ($locale === null) {
  602. $locale = $this->_options['locale'];
  603. }
  604. if (!Zend_Locale::isLocale($locale, true, false)) {
  605. if (!Zend_Locale::isLocale($locale, false, false)) {
  606. // language does not exist, return original string
  607. return false;
  608. }
  609. $locale = new Zend_Locale($locale);
  610. }
  611. $locale = (string) $locale;
  612. if (isset($this->_translate[$locale][$messageId]) === true) {
  613. // return original translation
  614. return true;
  615. } else if ((strlen($locale) != 2) and ($original === false)) {
  616. // faster than creating a new locale and separate the leading part
  617. $locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
  618. if (isset($this->_translate[$locale][$messageId]) === true) {
  619. // return regionless translation (en_US -> en)
  620. return true;
  621. }
  622. }
  623. // No translation found, return original
  624. return false;
  625. }
  626. /**
  627. * Returns the set cache
  628. *
  629. * @return Zend_Cache_Core The set cache
  630. */
  631. public static function getCache()
  632. {
  633. return self::$_cache;
  634. }
  635. /**
  636. * Sets a cache for all Zend_Translate_Adapters
  637. *
  638. * @param Zend_Cache_Core $cache Cache to store to
  639. */
  640. public static function setCache(Zend_Cache_Core $cache)
  641. {
  642. self::$_cache = $cache;
  643. }
  644. /**
  645. * Returns true when a cache is set
  646. *
  647. * @return boolean
  648. */
  649. public static function hasCache()
  650. {
  651. if (self::$_cache !== null) {
  652. return true;
  653. }
  654. return false;
  655. }
  656. /**
  657. * Removes any set cache
  658. *
  659. * @return void
  660. */
  661. public static function removeCache()
  662. {
  663. self::$_cache = null;
  664. }
  665. /**
  666. * Clears all set cache data
  667. *
  668. * @return void
  669. */
  670. public static function clearCache()
  671. {
  672. require_once 'Zend/Cache.php';
  673. self::$_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('Zend_Translate'));
  674. }
  675. /**
  676. * Returns the adapter name
  677. *
  678. * @return string
  679. */
  680. abstract public function toString();
  681. }