Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 /**
  * 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;
 }
 /**
  * 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];
 }
Exemple #4
0
 /**
  * Display the bar View.
  *
  * @param string $task The actual task
  *
  * @todo move
  *
  * @return string
  */
 private function displayBar($task)
 {
     $sel_language = JFactory::getApplication()->input->get('sel_language');
     $this->sel_language = $sel_language;
     $subTasks = array(array('title' => jgettext('Setup'), 'description' => jgettext('Setup your language files'), 'icon' => 'apply', 'task' => 'languages'), array('title' => jgettext('Files and menus'), 'description' => jgettext('Searches inside the source files and menus for translatable strings'), 'icon' => 'ecr_language', 'task' => 'searchfiles'), array('title' => jgettext('Translations'), 'description' => jgettext('Manage translations in ini files and inspect your php / xml files for JText strings to translate.'), 'icon' => 'ecr_language', 'task' => 'translations'), array('title' => jgettext('Default file order'), 'description' => jgettext('Change the order of your default language file and add comments to create a structure.'), 'icon' => 'text', 'task' => 'langcorrectdeforder'), array('title' => jgettext('Translation order'), 'description' => jgettext('Change the order of your translated language files according to your default file.'), 'icon' => 'text', 'task' => 'langcorrectorder'), array('title' => jgettext('Versions'), 'description' => jgettext('Compare saved versions of your language files.'), 'icon' => 'sig', 'task' => 'show_versions'), array('title' => jgettext('Convert'), 'description' => jgettext('Convert your language files and your code simultaneously.'), 'icon' => 'rename', 'task' => 'convert'));
     //@todo - unify..
     $html = '';
     $html .= EcrHtmlMenu::sub($subTasks);
     $html .= '<div style="clear: both; height: 1em;"></div>';
     //-- Scope selector
     if ($task != 'languages') {
         $html .= '<div class="ecr_menu_box" style="margin-left: 0.3em;">';
         $html .= jgettext('Scope') . '&nbsp;';
         $html .= '<select name="scope" class="span1" onchange="submitbutton(\'' . $task . '\');">';
         foreach ($this->project->getLanguagePaths() as $scope => $p) {
             $html .= '<option value="' . $scope . '" ';
             $html .= $this->scope == $scope ? ' selected="selected"' : '';
             $html .= '>';
             $html .= $scope . '</option>';
         }
         $html .= '</select>';
         $html .= '</div>';
     }
     switch ($task) {
         case 'translations':
         case 'searchfiles':
             if (count($this->project->langs) > 2) {
                 $html .= '<div class="ecr_menu_box">';
                 $html .= jgettext('Do NOT show') . ': ';
                 foreach ($this->project->langs as $lang => $scopes) {
                     if ($lang == 'en-GB') {
                         //-- Always show default language
                         continue;
                     }
                     $checked = in_array($lang, $this->hideLangs) ? 'checked="checked"' : '';
                     $color = in_array($lang, $this->hideLangs) ? 'red' : 'green';
                     $html .= '<input type="checkbox" name="hide_langs[]"' . ' id="hide_langs_' . $lang . '"' . ' value="' . $lang . '" ' . $checked . ' onclick="submitbutton(\'' . $task . '\');">';
                     $html .= '<label class="inline" for="hide_langs_' . $lang . '" style="color: ' . $color . ';">' . $lang . '</label>';
                 }
                 $html .= '</div>';
             }
             break;
         case 'langcorrectorder':
         case 'save_lang_corrected':
             $html .= '<div class="ecr_menu_box">';
             $html .= $this->drawLangSelector($sel_language, 'langcorrectorder');
             $html .= '  </div>';
             if ($sel_language) {
                 $html .= '<div class="ecr_menu_box">';
                 $html .= jgettext('Cut');
                 $cut_after = JFactory::getApplication()->input->getInt('cut_after', 30);
                 $html .= '<select name="cut_after" onchange="submitbutton(\'langcorrectorder\');">';
                 for ($i = 10; $i < 62; $i = $i + 2) {
                     $selected = $cut_after == $i ? ' selected="selected"' : '';
                     $html .= '<option value="' . $i . '" ' . $selected . '>' . $i . '</option>';
                 }
                 //for
                 $html .= '</select>';
                 $html .= '</div>';
                 $html .= EcrHtmlCheck::versioned();
                 $html .= '&nbsp;&nbsp;<span class="ecr_button img icon16-ecr_save"' . ' onclick="submitbutton(\'save_lang_corrected\');" style="display: inline !important;">';
                 $html .= jgettext('Save');
                 $html .= '  </span>';
             }
             break;
         case 'langcorrectdeforder':
         case 'save_deflang_corrected':
             $html .= EcrHtmlCheck::versioned();
             $html .= '<span class="btn img icon16-ecr_save"';
             $html .= 'onclick="submitbutton(\'save_deflang_corrected\');">' . jgettext('Save') . '</span>';
             $html .= '<br /><br /><div class="explanation">' . jgettext('Drag and drop elements to rearrange. Add new comments.') . '</div>';
             break;
         case 'show_versions':
         case 'show_version':
             $html .= '<div class="ecr_menu_box">';
             $html .= $this->drawLangSelector($sel_language, 'show_versions', true);
             $html .= '</div>';
             break;
         case 'translate':
         case 'language_check':
         case 'languages':
         case 'convert':
         case 'jalhoo':
             //-- Do nothing
             break;
         default:
             echo 'UNDEFINED: ' . $task;
             break;
     }
     //switch
     return $html;
 }
Exemple #5
0
 /**
  * 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 '';
 }