~fusonic/chive/1.1

« back to all changes in this revision

Viewing changes to yii/i18n/CPhpMessageSource.php

  • Committer: Matthias Burtscher
  • Date: 2010-02-12 09:12:35 UTC
  • Revision ID: matthias.burtscher@fusonic.net-20100212091235-jqxrb62klx872ajc
* Updated Yii to 1.1.0
* Removed CodePress and CodeMirror
* Updated jQuery and some plugins
* Cleaned some code ...

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *
5
5
 * @author Qiang Xue <qiang.xue@gmail.com>
6
6
 * @link http://www.yiiframework.com/
7
 
 * @copyright Copyright &copy; 2008-2009 Yii Software LLC
 
7
 * @copyright Copyright &copy; 2008-2010 Yii Software LLC
8
8
 * @license http://www.yiiframework.com/license/
9
9
 */
10
10
 
29
29
 * </ul>
30
30
 * When {@link cachingDuration} is set as a positive number, message translations will be cached.
31
31
 *
 
32
 * Starting from version 1.0.10, messages for an extension class (e.g. a widget, a module) can be specially managed and used.
 
33
 * In particular, if a message belongs to an extension whose class name is Xyz, then the message category
 
34
 * can be specified in the format of 'Xyz.categoryName'. And the corresponding message file
 
35
 * is assumed to be 'BasePath/messages/LanguageID/categoryName.php', where 'BasePath' refers to
 
36
 * the directory that contains the extension class file. When using Yii::t() to translate an extension message,
 
37
 * we should use: Yii::t('Xyz.categoryName', 'message to be translated').
 
38
 *
32
39
 * @author Qiang Xue <qiang.xue@gmail.com>
33
 
 * @version $Id: CPhpMessageSource.php 433 2008-12-30 22:59:17Z qiang.xue $
 
40
 * @version $Id: CPhpMessageSource.php 1678 2010-01-07 21:02:00Z qiang.xue $
34
41
 * @package system.i18n
35
42
 * @since 1.0
36
43
 */
44
51
         */
45
52
        public $cachingDuration=0;
46
53
        /**
 
54
         * @var string the ID of the cache application component that is used to cache the messages.
 
55
         * Defaults to 'cache' which refers to the primary cache application component.
 
56
         * Set this property to false if you want to disable caching the messages.
 
57
         * @since 1.0.10
 
58
         */
 
59
        public $cacheID='cache';
 
60
        /**
47
61
         * @var string the base path for all translated messages. Defaults to null, meaning
48
62
         * the "messages" subdirectory of the application directory (e.g. "protected/messages").
49
63
         */
50
64
        public $basePath;
51
65
 
 
66
        private $_files=array();
 
67
 
52
68
        /**
53
69
         * Initializes the application component.
54
70
         * This method overrides the parent implementation by preprocessing
62
78
        }
63
79
 
64
80
        /**
 
81
         * Determines the message file name based on the given category and language.
 
82
         * If the category name contains a dot, it will be split into the module class name and the category name.
 
83
         * In this case, the message file will be assumed to be located within the 'messages' subdirectory of
 
84
         * the directory containing the module class file.
 
85
         * Otherwise, the message file is assumed to be under the {@link basePath}.
 
86
         * @param string category name
 
87
         * @param string language ID
 
88
         * @return string the message file path
 
89
         * @since 1.0.10
 
90
         */
 
91
        protected function getMessageFile($category,$language)
 
92
        {
 
93
                if(!isset($this->_files[$category][$language]))
 
94
                {
 
95
                        if(($pos=strpos($category,'.'))!==false)
 
96
                        {
 
97
                                $moduleClass=substr($category,0,$pos);
 
98
                                $moduleCategory=substr($category,$pos+1);
 
99
                                $class=new ReflectionClass($moduleClass);
 
100
                                $this->_files[$category][$language]=dirname($class->getFileName()).DIRECTORY_SEPARATOR.'messages'.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.$moduleCategory.'.php';
 
101
                        }
 
102
                        else
 
103
                                $this->_files[$category][$language]=$this->basePath.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.$category.'.php';
 
104
                }
 
105
                return $this->_files[$category][$language];
 
106
        }
 
107
 
 
108
        /**
65
109
         * Loads the message translation for the specified language and category.
66
110
         * @param string the message category
67
111
         * @param string the target language
69
113
         */
70
114
        protected function loadMessages($category,$language)
71
115
        {
72
 
                $messageFile=$this->basePath.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.$category.'.php';
 
116
                $messageFile=$this->getMessageFile($category,$language);
73
117
 
74
 
                if($this->cachingDuration>0 && ($cache=Yii::app()->getCache())!==null)
 
118
                if($this->cachingDuration>0 && $this->cacheID!==false && ($cache=Yii::app()->getComponent($this->cacheID))!==null)
75
119
                {
76
120
                        $key=self::CACHE_KEY_PREFIX . $messageFile;
77
121
                        if(($data=$cache->get($key))!==false)