/** * Copy language files. * * @deprecated * * @return EcrProjectZiper */ private function copyLanguage() { //-- No languages defined if (false == is_array($this->project->langs)) { return $this; } //-- Only ini files needs to be copied if ($this->project->langFormat != 'ini') { return $this; } foreach ($this->project->langs as $language => $scopes) { foreach ($scopes as $scope) { $this->logger->log('<strong>Processing language ' . $language . ' - ' . $scope . '</strong>'); $paths = $this->project->getLanguagePaths($scope); if (false == is_array($paths)) { $paths = array($paths); } if (0 == count($paths)) { continue; } $found = false; $srcPath = ''; $srcFileName = ''; foreach ($paths as $path) { $srcFileName = $language . '.' . $this->project->getLanguageFileName($scope); $srcPath = $path . '/language/' . $language; if (file_exists($srcPath . '/' . $srcFileName)) { $found = true; break; } } if (false == $found) { $this->logger->log('File: ' . $srcPath . '/' . $srcFileName, 'copy failed'); $this->setError(sprintf(jgettext('File not found: %s'), $srcPath . '/' . $srcFileName)); continue; } $s = $scope; if (in_array($scope, array('menu', 'sys'))) { $s = 'admin' == $this->project->scope ? 'admin' : 'site'; } //$s = ($scope === 'menu' || $scope === 'sys') ? 'admin' : $scope; $tmp_dest = $this->temp_dir . DS . $s . DS . 'language' . DS . $language; if ($this->project->type == 'plugin') { $tmp_dest = $this->temp_dir . DS . 'site' . DS . 'language' . DS . $language; } if (file_exists($tmp_dest . DS . $srcFileName)) { $this->logger->log('File: ' . $srcFileName . ' already exists'); } else { JFolder::create($tmp_dest); if (JFile::copy($srcPath . '/' . $srcFileName, $tmp_dest . DS . $srcFileName)) { $this->logger->log('copy: ' . $srcFileName); } else { $this->logger->log('File: ' . $srcFileName, 'copy failed'); $this->setError(sprintf(jgettext('Failed to copy file %s to %s'), $srcPath . '/' . $srcFileName, $tmp_dest . DS . $srcFileName)); } } } } return $this; }
/** * Discover the languages for a project. * * @param EcrProjectBase $project The project * * @return array */ public static function discoverLanguages(EcrProjectBase $project) { static $languages = array(); $pKey = $project->type . $project->scope . $project->comName; if (isset($languages[$pKey])) { return $languages[$pKey]; } $langs = JFactory::getLanguage()->getKnownLanguages(); if (count($langs > 1)) { //-- We have more than one language.. order en-GB at first position $enGB = array('en-GB' => $langs['en-GB']); unset($langs['en-GB']); $langs = $enGB + $langs; } $languages[$pKey] = array(); $langPaths = $project->getLanguagePaths(); if (!$langPaths) { return array(); } foreach ($langs as $tag => $lang) { foreach ($langPaths as $scope => $paths) { if (!is_array($paths)) { $paths = array($paths); } foreach ($paths as $path) { if ($project->langFormat != 'ini') { //-- Special g11n Language $addPath = $tag . '/' . $tag . '.' . $project->getLanguageFileName($scope); } else { $addPath = 'language/' . $tag . '/' . $tag . '.' . $project->getLanguageFileName($scope); } $fileName = JPath::clean($path . '/' . $addPath); if (JFile::exists($fileName)) { $languages[$pKey][$tag][] = $scope; } } //foreach } //foreach } //foreach return $languages[$pKey]; }
/** * Scans the project. * * @return void */ private function scan() { foreach ($this->project->copies as $copy) { if (is_dir($copy)) { //-- Process known extensions foreach ($this->fileExtensions as $ext) { $data = $this->getCodeLines($copy, $ext); $this->addData($data, $ext); } //foreach //-- Process images $files = JFolder::files($copy, $this->imgExtensions, true, true); $this->projectData['images']['files'] += count($files); foreach ($files as $file) { $this->projectData['images']['size'] += filesize($file); } //foreach $this->totalFiles += $this->projectData['images']['files']; $this->totalSize += $this->projectData['images']['size']; } else { //-- It's a file //... @todo ? //-- Process known extensions foreach ($this->fileExtensions as $ext) { $data = $this->getCodeLines($copy, $ext); $this->addData($data, $ext); } //foreach } } //foreach /* * Language files */ $langPaths = $this->project->getLanguagePaths(); $languages = EcrLanguageHelper::discoverLanguages($this->project); foreach ($languages as $tag => $scopes) { foreach ($scopes as $scope) { $fileName = $langPaths[$scope] . DS . 'language' . DS . $tag . DS . $tag . '.' . $this->project->getLanguageFileName($scope); $data = $this->getCodeLines($fileName, 'ini'); $this->addData($data, 'languages'); } //foreach } //foreach return $this; }
/** * Generates a language file name. * * @param string $lang Language code eg. en-GB * @param string $scope Eg. admin * @param EcrProjectBase $project The EcrProject * * @return string full path to file */ public static function getFileName($lang, $scope, EcrProjectBase $project) { $paths = $project->getLanguagePaths($scope); if (!is_array($paths)) { $paths = array($paths); } if ($project->langFormat != 'ini') { //-- Special g11n Language $addPath = $lang . '/' . $lang . '.' . $project->getLanguageFileName($scope); } else { $addPath = 'language/' . $lang . '/' . $lang . '.' . $project->getLanguageFileName($scope); } foreach ($paths as $path) { if (file_exists($path . DS . $addPath)) { return $path . DS . $addPath; } } //foreach //-- No existing file found. //-- Return a valid new file name based on the scope if (isset($paths[$scope])) { return $paths[$scope] . DS . $addPath; } if (isset($paths[0])) { return $paths[0] . DS . $addPath; } //-- Found nothing :( return ''; }