/** * Create or update a language file. * * @static * * @param $extension * @param $scope * @param $lang * * @return mixed|string * @throws Exception */ public static function updateLanguage($extension, $scope, $lang) { $languageFile = g11nExtensionHelper::findLanguageFile($lang, $extension, $scope); $templateFile = g11nStorage::getTemplatePath($extension, $scope); $msg = ''; if (false == $languageFile) { //-- New file $scopePath = g11nExtensionHelper::getScopePath($scope); $extensionPath = g11nExtensionHelper::getExtensionLanguagePath($extension); $path = $scopePath . '/' . $extensionPath . '/' . $lang; if (!JFolder::exists($path)) { if (!JFolder::create($path)) { throw new Exception('Can not create the language folder'); } } $fileName = $lang . '.' . $extension . '.po'; $input = '--input=' . $templateFile; $output = '--output=' . $path . '/' . $fileName; $noWrap = '--no-wrap'; $locale = '--locale=' . $lang; $cmd = "msginit {$input} {$output} {$locale} {$noWrap} 2>&1"; $msg .= ECR_DEBUG ? '<h3>' . $cmd . '</h3>' : ''; ob_start(); system($cmd); $msg .= ob_get_clean(); $msg = str_replace("\n", BR, $msg); if (!JFile::exists($templateFile)) { throw new Exception('Can not copy create the language file'); } $msg = jgettext('The language file has been created<br />') . $msg; } else { //-- Update existing file $msg .= jgettext('Updating language file...'); $update = '--update'; $backup = '--backup=numbered'; $noFuzzy = '--no-fuzzy-matching'; $verbose = '--verbose'; $noWrap = '--no-wrap'; $cmd = "msgmerge {$update} {$noFuzzy} {$backup} {$verbose} {$noWrap} {$languageFile} {$templateFile} 2>&1"; $msg .= ECR_DEBUG ? '<h3>' . $cmd . '</h3>' : ''; ob_start(); system($cmd); $msg .= ob_get_clean(); } return $msg; }
/** * @return \stdClass */ private function getG11nInfo() { $info = new stdClass(); $this->languages = Ecrg11nHelper::getLanguages(); $baseLink = ''; $info->scope = $this->project->scope ? $this->project->scope : 'admin'; $info->id = $this->project->dbId; $info->extension = $this->project->comName; switch ($this->project->type) { case 'component': $comName = $this->project->comName; break; case 'plugin': $comName = 'plg_content_' . $this->project->comName; break; case 'template': $comName = 'tpl_' . $this->project->comName; break; default: echo 'undefined type: ' . $this->project->type; $comName = $this->project->comName; break; } //switch $info->exists = g11nExtensionHelper::isExtension($comName, $info->scope); $info->templateLink = $info->exists ? $baseLink . '&task=g11n.createTemplate&extension=' . $this->project->comName : ''; $cachedFiles = Ecrg11nHelper::getCachedFiles(); $this->scopes = array('admin' => JPATH_ADMINISTRATOR, 'site' => JPATH_SITE); $baseLink = 'index.php?option=com_g11n'; $info->editLink = $baseLink . '&task=g11n.edit'; $info->templateCommands = array(); $info->updateLinks = array(); $info->cacheLinks = array(); $types = array(''); $options = new JRegistry($this->project->buildOpts); if ('ON' == $options->get('lng_separate_javascript')) { $types[] = '.js'; } $types[] = '.config'; $extensionName = $this->project->comName; if (strpos($extensionName, '.')) { $extensionName = substr($extensionName, 0, strpos($extensionName, '.')); } foreach ($this->scopes as $scope => $path) { foreach ($types as $type) { if ('.config' == $type && 'admin' != $scope) { continue; } $scopeType = $scope . $type; if (!isset($this->languages[$scopeType])) { $this->languages[$scopeType] = $this->languages[$scope]; } try { $info->templateExists[$scopeType] = g11nStorage::templateExists($comName . $type, $scope); } catch (Exception $e) { $info->templateCommands[$scopeType] = $e->getMessage(); $info->templateLink = ''; } //try try { $info->templateStatus[$scopeType] = g11nStorage::templateExists($comName . $type, $scope); } catch (Exception $e) { $info->templateStatus[$scopeType] = $e->getMessage(); echo ''; } //try foreach ($this->languages[$scopeType] as $lang) { $exists = g11nExtensionHelper::findLanguageFile($lang['tag'], $comName . $type, $scope); $info->fileStatus[$scopeType][$lang['tag']] = $exists ? true : false; // g11nExtensionHelper::findLanguageFile($lang['tag'] // , $item->extension, $scope); $link = $baseLink . '&task=utility.updateLanguage'; $link .= '&extension=' . $info->extension . '&scope=' . $scope; $link .= '&langTag=' . $lang['tag']; $info->updateLinks[$scopeType][$lang['tag']] = $link; if (!array_key_exists($extensionName, $cachedFiles) || !array_key_exists($scope, $cachedFiles[$extensionName])) { $info->cacheStatus[$scopeType][$lang['tag']] = false; continue; } $info->cacheStatus[$scopeType][$lang['tag']] = false; $fName = $lang['tag'] . '.' . $this->project->comName; foreach ($cachedFiles[$extensionName][$scope] as $file) { if (strpos($file, $fName) === 0) { $info->cacheStatus[$scope][$lang['tag']] = true; } } //foreach } //foreach } //foreach } return $info; }