コード例 #1
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];
 }
コード例 #2
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];
 }
コード例 #3
0
ファイル: ICMessageSource.php プロジェクト: AxelPanda/ibos
 public function loadMessages($category, $language)
 {
     return parent::loadMessages($category, $language);
 }