Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage
  • Mage_Adminhtml_Block_Html_Date
  • Mage_Adminhtml_Block_Html_Select
  • Mage_Api_Model_Wsdl_Config_Element
  • Mage_Captcha_Adminhtml_RefreshController
  • Mage_Captcha_RefreshController
  • Mage_Core_AjaxController
  • Mage_Core_Block_Abstract
  • Mage_Core_Block_Flush
  • Mage_Core_Block_Html_Calendar
  • Mage_Core_Block_Html_Date
  • Mage_Core_Block_Html_Link
  • Mage_Core_Block_Html_Select
  • Mage_Core_Block_Messages
  • Mage_Core_Block_Profiler
  • Mage_Core_Block_Store_Switcher
  • Mage_Core_Block_Template
  • Mage_Core_Block_Template_Facade
  • Mage_Core_Block_Template_Smarty
  • Mage_Core_Block_Template_Zend
  • Mage_Core_Block_Text
  • Mage_Core_Block_Text_List
  • Mage_Core_Block_Text_List_Item
  • Mage_Core_Block_Text_List_Link
  • Mage_Core_Block_Text_Tag
  • Mage_Core_Block_Text_Tag_Css
  • Mage_Core_Block_Text_Tag_Css_Admin
  • Mage_Core_Block_Text_Tag_Debug
  • Mage_Core_Block_Text_Tag_Js
  • Mage_Core_Block_Text_Tag_Meta
  • Mage_Core_Controller_Front_Action
  • Mage_Core_Controller_Front_Router
  • Mage_Core_Controller_Request_Http
  • Mage_Core_Controller_Response_Http
  • Mage_Core_Controller_Varien_Action
  • Mage_Core_Controller_Varien_Front
  • Mage_Core_Controller_Varien_Router_Abstract
  • Mage_Core_Controller_Varien_Router_Admin
  • Mage_Core_Controller_Varien_Router_Default
  • Mage_Core_Controller_Varien_Router_Standard
  • Mage_Core_Helper_Abstract
  • Mage_Core_Helper_Cookie
  • Mage_Core_Helper_Data
  • Mage_Core_Helper_File_Storage
  • Mage_Core_Helper_File_Storage_Database
  • Mage_Core_Helper_Hint
  • Mage_Core_Helper_Http
  • Mage_Core_Helper_Js
  • Mage_Core_Helper_String
  • Mage_Core_Helper_Translate
  • Mage_Core_Helper_Url
  • Mage_Core_Helper_Url_Rewrite
  • Mage_Core_IndexController
  • Mage_Core_Model_Abstract
  • Mage_Core_Model_App
  • Mage_Core_Model_App_Area
  • Mage_Core_Model_App_Emulation
  • Mage_Core_Model_Cache
  • Mage_Core_Model_Calculator
  • Mage_Core_Model_Config
  • Mage_Core_Model_Config_Base
  • Mage_Core_Model_Config_Data
  • Mage_Core_Model_Config_Element
  • Mage_Core_Model_Config_Options
  • Mage_Core_Model_Config_System
  • Mage_Core_Model_Cookie
  • Mage_Core_Model_Date
  • Mage_Core_Model_Design
  • Mage_Core_Model_Design_Package
  • Mage_Core_Model_Design_Source_Design
  • Mage_Core_Model_Email
  • Mage_Core_Model_Email_Info
  • Mage_Core_Model_Email_Template
  • Mage_Core_Model_Email_Template_Filter
  • Mage_Core_Model_Email_Template_Mailer
  • Mage_Core_Model_Email_Transport
  • Mage_Core_Model_Encryption
  • Mage_Core_Model_File_Storage
  • Mage_Core_Model_File_Storage_Abstract
  • Mage_Core_Model_File_Storage_Database
  • Mage_Core_Model_File_Storage_Database_Abstract
  • Mage_Core_Model_File_Storage_Directory_Database
  • Mage_Core_Model_File_Storage_File
  • Mage_Core_Model_File_Storage_Flag
  • Mage_Core_Model_File_Uploader
  • Mage_Core_Model_File_Validator_AvailablePath
  • Mage_Core_Model_File_Validator_NotProtectedExtension
  • Mage_Core_Model_Flag
  • Mage_Core_Model_Input_Filter
  • Mage_Core_Model_Input_Filter_MaliciousCode
  • Mage_Core_Model_Language
  • Mage_Core_Model_Layout
  • Mage_Core_Model_Layout_Data
  • Mage_Core_Model_Layout_Element
  • Mage_Core_Model_Layout_Update
  • Mage_Core_Model_Locale
  • Mage_Core_Model_Locale_Config
  • Mage_Core_Model_Log_Adapter
  • Mage_Core_Model_Magento_Api
  • Mage_Core_Model_Magento_Api_V2
  • Mage_Core_Model_Message
  • Mage_Core_Model_Message_Abstract
  • Mage_Core_Model_Message_Collection
  • Mage_Core_Model_Message_Error
  • Mage_Core_Model_Message_Notice
  • Mage_Core_Model_Message_Success
  • Mage_Core_Model_Message_Warning
  • Mage_Core_Model_Mysql4_Abstract
  • Mage_Core_Model_Mysql4_Cache
  • Mage_Core_Model_Mysql4_Collection_Abstract
  • Mage_Core_Model_Mysql4_Config
  • Mage_Core_Model_Mysql4_Config_Data
  • Mage_Core_Model_Mysql4_Config_Data_Collection
  • Mage_Core_Model_Mysql4_Design
  • Mage_Core_Model_Mysql4_Design_Collection
  • Mage_Core_Model_Mysql4_Design_Package_Collection
  • Mage_Core_Model_Mysql4_Design_Theme
  • Mage_Core_Model_Mysql4_Email_Template
  • Mage_Core_Model_Mysql4_Email_Template_Collection
  • Mage_Core_Model_Mysql4_File_Storage_Abstract
  • Mage_Core_Model_Mysql4_File_Storage_Database
  • Mage_Core_Model_Mysql4_File_Storage_Directory_Database
  • Mage_Core_Model_Mysql4_File_Storage_File
  • Mage_Core_Model_Mysql4_Flag
  • Mage_Core_Model_Mysql4_Language
  • Mage_Core_Model_Mysql4_Language_Collection
  • Mage_Core_Model_Mysql4_Layout
  • Mage_Core_Model_Mysql4_Resource
  • Mage_Core_Model_Mysql4_Session
  • Mage_Core_Model_Mysql4_Store
  • Mage_Core_Model_Mysql4_Store_Collection
  • Mage_Core_Model_Mysql4_Store_Group
  • Mage_Core_Model_Mysql4_Store_Group_Collection
  • Mage_Core_Model_Mysql4_Translate
  • Mage_Core_Model_Mysql4_Translate_String
  • Mage_Core_Model_Mysql4_Url_Rewrite
  • Mage_Core_Model_Mysql4_Url_Rewrite_Collection
  • Mage_Core_Model_Mysql4_Variable
  • Mage_Core_Model_Mysql4_Variable_Collection
  • Mage_Core_Model_Mysql4_Website
  • Mage_Core_Model_Mysql4_Website_Collection
  • Mage_Core_Model_Observer
  • Mage_Core_Model_Resource
  • Mage_Core_Model_Resource_Abstract
  • Mage_Core_Model_Resource_Cache
  • Mage_Core_Model_Resource_Config
  • Mage_Core_Model_Resource_Config_Data
  • Mage_Core_Model_Resource_Config_Data_Collection
  • Mage_Core_Model_Resource_Db_Abstract
  • Mage_Core_Model_Resource_Db_Collection_Abstract
  • Mage_Core_Model_Resource_Design
  • Mage_Core_Model_Resource_Design_Collection
  • Mage_Core_Model_Resource_Design_Package_Collection
  • Mage_Core_Model_Resource_Email_Template
  • Mage_Core_Model_Resource_Email_Template_Collection
  • Mage_Core_Model_Resource_Entity_Abstract
  • Mage_Core_Model_Resource_Entity_Table
  • Mage_Core_Model_Resource_File_Storage_Abstract
  • Mage_Core_Model_Resource_File_Storage_Database
  • Mage_Core_Model_Resource_File_Storage_Directory_Database
  • Mage_Core_Model_Resource_File_Storage_File
  • Mage_Core_Model_Resource_Flag
  • Mage_Core_Model_Resource_Helper_Abstract
  • Mage_Core_Model_Resource_Helper_Mysql4
  • Mage_Core_Model_Resource_Iterator
  • Mage_Core_Model_Resource_Language
  • Mage_Core_Model_Resource_Language_Collection
  • Mage_Core_Model_Resource_Layout
  • Mage_Core_Model_Resource_Resource
  • Mage_Core_Model_Resource_Session
  • Mage_Core_Model_Resource_Setup
  • Mage_Core_Model_Resource_Setup_Query_Modifier
  • Mage_Core_Model_Resource_Store
  • Mage_Core_Model_Resource_Store_Collection
  • Mage_Core_Model_Resource_Store_Group
  • Mage_Core_Model_Resource_Store_Group_Collection
  • Mage_Core_Model_Resource_Transaction
  • Mage_Core_Model_Resource_Translate
  • Mage_Core_Model_Resource_Translate_String
  • Mage_Core_Model_Resource_Type_Abstract
  • Mage_Core_Model_Resource_Type_Db
  • Mage_Core_Model_Resource_Type_Db_Mysqli
  • Mage_Core_Model_Resource_Type_Db_Mysqli_Setup
  • Mage_Core_Model_Resource_Type_Db_Pdo_Mysql
  • Mage_Core_Model_Resource_Url_Rewrite
  • Mage_Core_Model_Resource_Url_Rewrite_Collection
  • Mage_Core_Model_Resource_Variable
  • Mage_Core_Model_Resource_Variable_Collection
  • Mage_Core_Model_Resource_Website
  • Mage_Core_Model_Resource_Website_Collection
  • Mage_Core_Model_Session
  • Mage_Core_Model_Session_Abstract
  • Mage_Core_Model_Session_Abstract_Varien
  • Mage_Core_Model_Session_Abstract_Zend
  • Mage_Core_Model_Source_Email_Variables
  • Mage_Core_Model_Store
  • Mage_Core_Model_Store_Api
  • Mage_Core_Model_Store_Api_V2
  • Mage_Core_Model_Store_Group
  • Mage_Core_Model_Template
  • Mage_Core_Model_Translate
  • Mage_Core_Model_Translate_Expr
  • Mage_Core_Model_Translate_Inline
  • Mage_Core_Model_Translate_String
  • Mage_Core_Model_Url
  • Mage_Core_Model_Url_Rewrite
  • Mage_Core_Model_Url_Validator
  • Mage_Core_Model_Variable
  • Mage_Core_Model_Variable_Config
  • Mage_Core_Model_Variable_Observer
  • Mage_Core_Model_Website
  • Mage_Page_Block_Switch
  • Mage_Page_Block_Template_Container
  • Mage_Page_Block_Template_Links
  • Mage_Page_Block_Template_Links_Block
  • Mage_Sales_Model_Quote_Address_Total_Collector

Exceptions

  • Mage_Core_Controller_Varien_Exception
  • Mage_Core_Exception
  • Mage_Core_Model_Session_Exception
  • Mage_Core_Model_Store_Exception

Functions

  • destruct
  • is_dir_writeable
  • is_empty_date
  • mageCoreErrorHandler
  • mageDebugBacktrace
  • mageDelTree
  • mageFindClassFile
  • mageParseCsv
  • mageSendErrorFooter
  • mageSendErrorHeader
  • mageUndoMagicQuotes
  • now
  • sys_get_temp_dir
  • uc_words
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 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@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Core
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Translate model
 29:  *
 30:  * @author      Magento Core Team <core@magentocommerce.com>
 31:  */
 32: class Mage_Core_Model_Translate
 33: {
 34:     const CSV_SEPARATOR     = ',';
 35:     const SCOPE_SEPARATOR   = '::';
 36:     const CACHE_TAG         = 'translate';
 37: 
 38:     const CONFIG_KEY_AREA   = 'area';
 39:     const CONFIG_KEY_LOCALE = 'locale';
 40:     const CONFIG_KEY_STORE  = 'store';
 41:     const CONFIG_KEY_DESIGN_PACKAGE = 'package';
 42:     const CONFIG_KEY_DESIGN_THEME   = 'theme';
 43: 
 44:     /**
 45:      * Locale name
 46:      *
 47:      * @var string
 48:      */
 49:     protected $_locale;
 50: 
 51:     /**
 52:      * Translation object
 53:      *
 54:      * @var Zend_Translate_Adapter
 55:      */
 56:     protected $_translate;
 57: 
 58:     /**
 59:      * Translator configuration array
 60:      *
 61:      * @var array
 62:      */
 63:     protected $_config;
 64: 
 65:     protected $_useCache = true;
 66: 
 67:     /**
 68:      * Cache identifier
 69:      *
 70:      * @var string
 71:      */
 72:     protected $_cacheId;
 73: 
 74:     /**
 75:      * Translation data
 76:      *
 77:      * @var array
 78:      */
 79:     protected $_data = array();
 80: 
 81:     /**
 82:      * Translation data for data scope (per module)
 83:      *
 84:      * @var array
 85:      */
 86:     protected $_dataScope;
 87: 
 88:     /**
 89:      * Configuration flag to enable inline translations
 90:      *
 91:      * @var boolean
 92:      */
 93:     protected $_translateInline;
 94: 
 95:     /**
 96:      * Configuration flag to local enable inline translations
 97:      *
 98:      * @var boolean
 99:      */
100:     protected $_canUseInline = true;
101: 
102:     public function __construct()
103:     {
104:     }
105: 
106:     /**
107:      * Initialization translation data
108:      *
109:      * @param   string $area
110:      * @return  Mage_Core_Model_Translate
111:      */
112:     public function init($area, $forceReload = false)
113:     {
114:         $this->setConfig(array(self::CONFIG_KEY_AREA=>$area));
115: 
116:         $this->_translateInline = Mage::getSingleton('core/translate_inline')
117:             ->isAllowed($area=='adminhtml' ? 'admin' : null);
118: 
119:         if (!$forceReload) {
120:             if ($this->_canUseCache()) {
121:                 $this->_data = $this->_loadCache();
122:                 if ($this->_data !== false) {
123:                     return $this;
124:                 }
125:             }
126:             Mage::app()->removeCache($this->getCacheId());
127:         }
128: 
129:         $this->_data = array();
130: 
131:         foreach ($this->getModulesConfig() as $moduleName=>$info) {
132:             $info = $info->asArray();
133:             $this->_loadModuleTranslation($moduleName, $info['files'], $forceReload);
134:         }
135: 
136:         $this->_loadThemeTranslation($forceReload);
137:         $this->_loadDbTranslation($forceReload);
138: 
139:         if (!$forceReload && $this->_canUseCache()) {
140:             $this->_saveCache();
141:         }
142: 
143:         return $this;
144:     }
145: 
146:     /**
147:      * Retrieve modules configuration by translation
148:      *
149:      * @return Mage_Core_Model_Config_Element
150:      */
151:     public function getModulesConfig()
152:     {
153:         if (!Mage::getConfig()->getNode($this->getConfig(self::CONFIG_KEY_AREA).'/translate/modules')) {
154:             return array();
155:         }
156: 
157:         $config = Mage::getConfig()->getNode($this->getConfig(self::CONFIG_KEY_AREA).'/translate/modules')->children();
158:         if (!$config) {
159:             return array();
160:         }
161:         return $config;
162:     }
163: 
164:     /**
165:      * Initialize configuration
166:      *
167:      * @param   array $config
168:      * @return  Mage_Core_Model_Translate
169:      */
170:     public function setConfig($config)
171:     {
172:         $this->_config = $config;
173:         if (!isset($this->_config[self::CONFIG_KEY_LOCALE])) {
174:             $this->_config[self::CONFIG_KEY_LOCALE] = $this->getLocale();
175:         }
176:         if (!isset($this->_config[self::CONFIG_KEY_STORE])) {
177:             $this->_config[self::CONFIG_KEY_STORE] = Mage::app()->getStore()->getId();
178:         }
179:         if (!isset($this->_config[self::CONFIG_KEY_DESIGN_PACKAGE])) {
180:             $this->_config[self::CONFIG_KEY_DESIGN_PACKAGE] = Mage::getDesign()->getPackageName();
181:         }
182:         if (!isset($this->_config[self::CONFIG_KEY_DESIGN_THEME])) {
183:             $this->_config[self::CONFIG_KEY_DESIGN_THEME] = Mage::getDesign()->getTheme('locale');
184:         }
185:         return $this;
186:     }
187: 
188:     /**
189:      * Retrieve config value by key
190:      *
191:      * @param   string $key
192:      * @return  mixed
193:      */
194:     public function getConfig($key)
195:     {
196:         if (isset($this->_config[$key])) {
197:             return $this->_config[$key];
198:         }
199:         return null;
200:     }
201: 
202:     /**
203:      * Loading data from module translation files
204:      *
205:      * @param   string $moduleName
206:      * @param   string $files
207:      * @return  Mage_Core_Model_Translate
208:      */
209:     protected function _loadModuleTranslation($moduleName, $files, $forceReload=false)
210:     {
211:         foreach ($files as $file) {
212:             $file = $this->_getModuleFilePath($moduleName, $file);
213:             $this->_addData($this->_getFileData($file), $moduleName, $forceReload);
214:         }
215:         return $this;
216:     }
217: 
218:     /**
219:      * Adding translation data
220:      *
221:      * @param array $data
222:      * @param string $scope
223:      * @return Mage_Core_Model_Translate
224:      */
225:     protected function _addData($data, $scope, $forceReload=false)
226:     {
227:         foreach ($data as $key => $value) {
228:             if ($key === $value) {
229:                 continue;
230:             }
231:             $key    = $this->_prepareDataString($key);
232:             $value  = $this->_prepareDataString($value);
233:             if ($scope && isset($this->_dataScope[$key]) && !$forceReload ) {
234:                 /**
235:                  * Checking previos value
236:                  */
237:                 $scopeKey = $this->_dataScope[$key] . self::SCOPE_SEPARATOR . $key;
238:                 if (!isset($this->_data[$scopeKey])) {
239:                     if (isset($this->_data[$key])) {
240:                         $this->_data[$scopeKey] = $this->_data[$key];
241:                         /**
242:                          * Not allow use translation not related to module
243:                          */
244:                         if (Mage::getIsDeveloperMode()) {
245:                             unset($this->_data[$key]);
246:                         }
247:                     }
248:                 }
249:                 $scopeKey = $scope . self::SCOPE_SEPARATOR . $key;
250:                 $this->_data[$scopeKey] = $value;
251:             }
252:             else {
253:                 $this->_data[$key]     = $value;
254:                 $this->_dataScope[$key]= $scope;
255:             }
256:         }
257:         return $this;
258:     }
259: 
260:     protected function _prepareDataString($string)
261:     {
262:         return str_replace('""', '"', $string);
263:     }
264: 
265:     /**
266:      * Loading current theme translation
267:      *
268:      * @return Mage_Core_Model_Translate
269:      */
270:     protected function _loadThemeTranslation($forceReload = false)
271:     {
272:         $file = Mage::getDesign()->getLocaleFileName('translate.csv');
273:         $this->_addData($this->_getFileData($file), false, $forceReload);
274:         return $this;
275:     }
276: 
277:     /**
278:      * Loading current store translation from DB
279:      *
280:      * @return Mage_Core_Model_Translate
281:      */
282:     protected function _loadDbTranslation($forceReload = false)
283:     {
284:         $arr = $this->getResource()->getTranslationArray(null, $this->getLocale());
285:         $this->_addData($arr, $this->getConfig(self::CONFIG_KEY_STORE), $forceReload);
286:         return $this;
287:     }
288: 
289:     /**
290:      * Retrieve translation file for module
291:      *
292:      * @param   string $module
293:      * @return  string
294:      */
295:     protected function _getModuleFilePath($module, $fileName)
296:     {
297:         //$file = Mage::getConfig()->getModuleDir('locale', $module);
298:         $file = Mage::getBaseDir('locale');
299:         $file.= DS.$this->getLocale().DS.$fileName;
300:         return $file;
301:     }
302: 
303:     /**
304:      * Retrieve data from file
305:      *
306:      * @param   string $file
307:      * @return  array
308:      */
309:     protected function _getFileData($file)
310:     {
311:         $data = array();
312:         if (file_exists($file)) {
313:             $parser = new Varien_File_Csv();
314:             $parser->setDelimiter(self::CSV_SEPARATOR);
315:             $data = $parser->getDataPairs($file);
316:         }
317:         return $data;
318:     }
319: 
320:     /**
321:      * Retrieve translation data
322:      *
323:      * @return array
324:      */
325:     public function getData()
326:     {
327:         if (is_null($this->_data)) {
328:             return array();
329:             //Mage::throwException('Translation data is not initialized. Please contact developers.');
330:         }
331:         return $this->_data;
332:     }
333: 
334:     /**
335:      * Retrieve locale
336:      *
337:      * @return string
338:      */
339:     public function getLocale()
340:     {
341:         if (is_null($this->_locale)) {
342:             $this->_locale = Mage::app()->getLocale()->getLocaleCode();
343:         }
344:         return $this->_locale;
345:     }
346: 
347:     public function setLocale( $locale )
348:     {
349:         $this->_locale = $locale;
350:         return $this;
351:     }
352: 
353:     /**
354:      * Retrieve DB resource model
355:      *
356:      * @return unknown
357:      */
358:     public function getResource()
359:     {
360:         return Mage::getResourceSingleton('core/translate');
361:     }
362: 
363:     /**
364:      * Retrieve translation object
365:      *
366:      * @return Zend_Translate_Adapter
367:      */
368:     public function getTranslate()
369:     {
370:         if (is_null($this->_translate)) {
371:             $this->_translate = new Zend_Translate('array', $this->getData(), $this->getLocale());
372:         }
373:         return $this->_translate;
374:     }
375: 
376:     /**
377:      * Translate
378:      *
379:      * @param   array $args
380:      * @return  string
381:      */
382:     public function translate($args)
383:     {
384:         $text = array_shift($args);
385: 
386:         if (is_string($text) && ''==$text
387:             || is_null($text)
388:             || is_bool($text) && false===$text
389:             || is_object($text) && ''==$text->getText()) {
390:             return '';
391:         }
392:         if ($text instanceof Mage_Core_Model_Translate_Expr) {
393:             $code = $text->getCode(self::SCOPE_SEPARATOR);
394:             $module = $text->getModule();
395:             $text = $text->getText();
396:             $translated = $this->_getTranslatedString($text, $code);
397:         }
398:         else {
399:             if (!empty($_REQUEST['theme'])) {
400:                 $module = 'frontend/default/'.$_REQUEST['theme'];
401:             } else {
402:                 $module = 'frontend/default/default';
403:             }
404:             $code = $module.self::SCOPE_SEPARATOR.$text;
405:             $translated = $this->_getTranslatedString($text, $code);
406:         }
407: 
408:         //array_unshift($args, $translated);
409:         //$result = @call_user_func_array('sprintf', $args);
410: 
411:         $result = @vsprintf($translated, $args);
412:         if ($result === false) {
413:             $result = $translated;
414:         }
415: 
416:         if ($this->_translateInline && $this->getTranslateInline()) {
417:             if (strpos($result, '{{{')===false || strpos($result, '}}}')===false || strpos($result, '}}{{')===false) {
418:                 $result = '{{{'.$result.'}}{{'.$translated.'}}{{'.$text.'}}{{'.$module.'}}}';
419:             }
420:         }
421: 
422:         return $result;
423:     }
424: 
425:     /**
426:      * Set Translate inline mode
427:      *
428:      * @param bool $flag
429:      * @return Mage_Core_Model_Translate
430:      */
431:     public function setTranslateInline($flag=null)
432:     {
433:         $this->_canUseInline = (bool) $flag;
434:         return $this;
435:     }
436: 
437:     /**
438:      * Retrieve active translate mode
439:      *
440:      * @return bool
441:      */
442:     public function getTranslateInline()
443:     {
444:         return $this->_canUseInline;
445:     }
446: 
447:     /**
448:      * Retrive translated template file
449:      *
450:      * @param string $file
451:      * @param string $type
452:      * @param string $localeCode
453:      * @return string
454:      */
455:     public function getTemplateFile($file, $type, $localeCode=null)
456:     {
457:         if (is_null($localeCode) || preg_match('/[^a-zA-Z_]/', $localeCode)) {
458:             $localeCode = $this->getLocale();
459:         }
460: 
461:         $filePath = Mage::getBaseDir('locale')  . DS
462:                   . $localeCode . DS . 'template' . DS . $type . DS . $file;
463: 
464:         if (!file_exists($filePath)) { // If no template specified for this locale, use store default
465:             $filePath = Mage::getBaseDir('locale') . DS
466:                       . Mage::app()->getLocale()->getDefaultLocale()
467:                       . DS . 'template' . DS . $type . DS . $file;
468:         }
469: 
470:         if (!file_exists($filePath)) {  // If no template specified as  store default locale, use en_US
471:             $filePath = Mage::getBaseDir('locale') . DS
472:                       . Mage_Core_Model_Locale::DEFAULT_LOCALE
473:                       . DS . 'template' . DS . $type . DS . $file;
474:         }
475: 
476:         $ioAdapter = new Varien_Io_File();
477:         $ioAdapter->open(array('path' => Mage::getBaseDir('locale')));
478: 
479:         return (string) $ioAdapter->read($filePath);
480:     }
481: 
482:     /**
483:      * Retrieve cache identifier
484:      *
485:      * @return string
486:      */
487:     public function getCacheId()
488:     {
489:         if (is_null($this->_cacheId)) {
490:             $this->_cacheId = 'translate';
491:             if (isset($this->_config[self::CONFIG_KEY_LOCALE])) {
492:                 $this->_cacheId.= '_'.$this->_config[self::CONFIG_KEY_LOCALE];
493:             }
494:             if (isset($this->_config[self::CONFIG_KEY_AREA])) {
495:                 $this->_cacheId.= '_'.$this->_config[self::CONFIG_KEY_AREA];
496:             }
497:             if (isset($this->_config[self::CONFIG_KEY_STORE])) {
498:                 $this->_cacheId.= '_'.$this->_config[self::CONFIG_KEY_STORE];
499:             }
500:             if (isset($this->_config[self::CONFIG_KEY_DESIGN_PACKAGE])) {
501:                 $this->_cacheId.= '_'.$this->_config[self::CONFIG_KEY_DESIGN_PACKAGE];
502:             }
503:             if (isset($this->_config[self::CONFIG_KEY_DESIGN_THEME])) {
504:                 $this->_cacheId.= '_'.$this->_config[self::CONFIG_KEY_DESIGN_THEME];
505:             }
506:         }
507:         return $this->_cacheId;
508:     }
509: 
510:     /**
511:      * Loading data cache
512:      *
513:      * @param   string $area
514:      * @return  array | false
515:      */
516:     protected function _loadCache()
517:     {
518:         if (!$this->_canUseCache()) {
519:             return false;
520:         }
521:         $data = Mage::app()->loadCache($this->getCacheId());
522:         $data = unserialize($data);
523:         return $data;
524:     }
525: 
526:     /**
527:      * Saving data cache
528:      *
529:      * @param   string $area
530:      * @return  Mage_Core_Model_Translate
531:      */
532:     protected function _saveCache()
533:     {
534:         if (!$this->_canUseCache()) {
535:             return $this;
536:         }
537:         Mage::app()->saveCache(serialize($this->getData()), $this->getCacheId(), array(self::CACHE_TAG), null);
538:         return $this;
539:     }
540: 
541:     /**
542:      * Check cache usage availability
543:      *
544:      * @return bool
545:      */
546:     protected function _canUseCache()
547:     {
548:         return Mage::app()->useCache('translate');
549:     }
550: 
551:     /**
552:      * Return translated string from text.
553:      *
554:      * @param string $text
555:      * @param string $code
556:      * @return string
557:      */
558:     protected function _getTranslatedString($text, $code)
559:     {
560:         $translated = '';
561:         if (array_key_exists($code, $this->getData())) {
562:             $translated = $this->_data[$code];
563:         }
564:         elseif (array_key_exists($text, $this->getData())) {
565:             $translated = $this->_data[$text];
566:         }
567:         else {
568:             $translated = $text;
569:         }
570:         return $translated;
571:     }
572: }
573: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0