Adapter.php 26 KB

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