Exemplo n.º 1
0
 /**
  * Initializes the application component.
  * This method overrides the parent implementation by preprocessing
  * the user request data.
  */
 public function init()
 {
     parent::init();
     if ($this->basePath === null) {
         $this->basePath = Yii::getPathOfAlias('application.messages');
     }
 }
Exemplo n.º 2
0
 /**
  * Loads the message translation for the specified language and category.
  *
  * @param string $category The message category
  * @param string $language The target locale
  *
  * @return array The loaded messages
  */
 protected function loadMessages($category, $language)
 {
     if ($category !== 'craft') {
         $parentMessages = parent::loadMessages($category, $language);
         // See if there any craft/translations for Yii's system messages.
         if (($filePath = IOHelper::fileExists(craft()->path->getSiteTranslationsPath() . $language . '.php')) !== false) {
             $parentMessages = array_merge($parentMessages, include $filePath);
         }
         return $parentMessages;
     }
     if (!isset($this->_translations[$language])) {
         $this->_translations[$language] = array();
         // Plugin translations get added first so they always lose out for conflicts
         if (craft()->isInstalled() && !craft()->isInMaintenanceMode()) {
             // Don't use PluginService, but go straight to the file system. Who cares if they are disabled.
             $pluginPaths = IOHelper::getFolders(craft()->path->getPluginsPath());
             if ($pluginPaths) {
                 foreach ($pluginPaths as $pluginPath) {
                     $paths[] = $pluginPath . 'translations/';
                 }
             }
         }
         // Craft's translations are up next
         $paths[] = craft()->path->getCpTranslationsPath();
         // Add in Yii's i18n data, which we're going to do some special parsing on
         $paths[] = craft()->path->getFrameworkPath() . 'i18n/data/';
         // Site translations take the highest precidence, so they get added last
         $paths[] = craft()->path->getSiteTranslationsPath();
         // Look for translation file from least to most specific. For example, nl.php gets loaded before nl_nl.php.
         $translationFiles = array();
         $parts = explode('_', $language);
         $totalParts = count($parts);
         for ($i = 1; $i <= $totalParts; $i++) {
             $translationFiles[] = implode('_', array_slice($parts, 0, $i));
         }
         // Now loop through all of the paths and translation files and import the ones that exist
         foreach ($paths as $folderPath) {
             if (IOHelper::folderExists($folderPath)) {
                 foreach ($translationFiles as $file) {
                     $path = $folderPath . $file . '.php';
                     if (IOHelper::fileExists($path)) {
                         // Load it up.
                         $translations = (include $path);
                         if (is_array($translations)) {
                             // If this is framework data and we're not on en_us, then do some special processing.
                             if (strpos($path, 'framework/i18n/data') !== false && $file !== 'en_us') {
                                 $translations = $this->_processFrameworkData($file);
                             }
                             $this->_translations[$language] = array_merge($this->_translations[$language], $translations);
                         }
                     }
                 }
             }
         }
     }
     return $this->_translations[$language];
 }
Exemplo n.º 3
0
 /**
  * Constructor
  * Sets the default basePath to webroot.themes.{{themename}}
  */
 public function init()
 {
     Yii::app()->language = Cii::setApplicationLanguage();
     parent::init();
     if (isset(Yii::app()->theme) && isset(Yii::app()->theme->name)) {
         $this->basePath = Yii::getPathOfAlias('base.themes.' . Yii::app()->theme->name . '.messages');
     } else {
         if (isset(Yii::app()->controller->module->id)) {
             $this->basePath = Yii::getPathOfAlias('application.modules.' . Yii::app()->controller->module->id);
         } else {
             $this->basePath = Yii::getPathOfAlias('application.modules.install');
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Loads the message translation for the specified language and category.
  *
  * @param string $category the message category
  * @param string $language the target language
  * @return array the loaded messages
  */
 protected function loadMessages($category, $language)
 {
     if ($category != 'craft') {
         return parent::loadMessages($category, $language);
     }
     if (!isset($this->_translations[$language])) {
         $this->_translations[$language] = array();
         $paths[] = craft()->path->getCpTranslationsPath();
         $paths[] = craft()->path->getSiteTranslationsPath();
         foreach ($paths as $path) {
             $file = $path . $language . '.php';
             if (IOHelper::fileExists($file)) {
                 $translations = (include $file);
                 if (is_array($translations)) {
                     $this->_translations[$language] = array_merge($this->_translations[$language], $translations);
                 }
             }
         }
     }
     return $this->_translations[$language];
 }
Exemplo n.º 5
0
 /**
  *
  */
 public function init()
 {
     $this->basePath = craft()->path->getFrameworkPath() . 'messages/';
     parent::init();
 }
Exemplo n.º 6
0
 /**
  * Initializes the application component.
  * This method overrides the parent implementation by preprocessing
  * the user request data.
  */
 public function init()
 {
     $this->basePath = Yii::getPathOfAlias('common.messages');
     parent::init();
 }
Exemplo n.º 7
0
 public function loadMessages($category, $language)
 {
     return parent::loadMessages($category, $language);
 }