Translate.php source code
Contents of file
Application/Resource/Translate.php
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_Application
17 * @subpackage Resource
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: Translate.php 16200 2009-06-21 18:50:06Z thomas $
21 */
22
23 /**
24 * Resource for setting translation options
25 *
26 * @uses Zend_Application_Resource_ResourceAbstract
27 * @category Zend
28 * @package Zend_Application
29 * @subpackage Resource
30 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
32 */
33 class Zend_Application_Resource_Translate extends Zend_Application_Resource_ResourceAbstract
34 {
35 const DEFAULT_REGISTRY_KEY = 'Zend_Translate';
36
37 /**
38 * @var Zend_Translate
39 */
40 protected $_translate;
41
42 /**
43 * Defined by Zend_Application_Resource_Resource
44 *
45 * @return Zend_Translate
46 */
47 public function init()
48 {
49 return $this->getTranslate();
50 }
51
52 /**
53 * Retrieve translate object
54 *
55 * @return Zend_Translate
56 */
57 public function getTranslate()
58 {
59 if (null === $this->_translate) {
60 $options = $this->getOptions();
61
62 if (!isset($options['data'])) {
63 throw new Zend_Application_Resource_Exception('No translation source data provided.');
64 }
65
66 $adapter = isset($options['adapter']) ? $options['adapter'] : Zend_Translate::AN_ARRAY;
67 $locale = isset($options['locale']) ? $options['locale'] : null;
68 $translateOptions = isset($options['options']) ? $options['options'] : array();
69
70 $this->_translate = new Zend_Translate(
71 $adapter, $options['data'], $locale, $translateOptions
72 );
73
74 $key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
75 ? $options['registry_key']
76 : self::DEFAULT_REGISTRY_KEY;
77
78 Zend_Registry::set($key, $this->_translate);
79 }
80
81 return $this->_translate;
82 }
83 }