/** * Extract information about the translators from the language files. * * @return array * * @since 1.0 */ private function checkLanguageFiles() { $list = array(); g11nExtensionHelper::addDomainPath('Core', JPATH_ROOT . '/src'); g11nExtensionHelper::addDomainPath('Template', JPATH_ROOT . '/templates'); g11nExtensionHelper::addDomainPath('App', JPATH_ROOT . '/src/App'); $scopes = array('Core' => array('JTracker'), 'Template' => array('JTracker'), 'App' => (new Filesystem(new Local(JPATH_ROOT . '/src/App')))->listPaths()); $langTags = $this->getApplication()->get('languages'); $noEmail = $this->getApplication()->input->get('noemail'); foreach ($langTags as $langTag) { if ('en-GB' == $langTag) { continue; } $langInfo = new \stdClass(); $langInfo->tag = $langTag; $langInfo->translators = array(); $translators = array(); foreach ($scopes as $domain => $extensions) { foreach ($extensions as $extension) { $path = g11nExtensionHelper::findLanguageFile($langTag, $extension, $domain); if (false == file_exists($path)) { $this->out(sprintf('Language file not found %s, %s, %s' . $langTag, $extension, $domain)); continue; } $f = fopen($path, 'r'); $line = '#'; $started = false; while ($line) { $line = fgets($f, 1000); if (0 !== strpos($line, '#')) { // Encountered the first line - We're done parsing. $line = ''; continue; } if (strpos($line, 'Translators:')) { // Start $started = true; continue; } if (!$started) { continue; } $line = trim($line, "# \n"); if ($noEmail) { // Strip off the e-mail address // Format: '<*****@*****.**>, ' $line = preg_replace('/<[a-z0-9\\.\\-+]+@[a-z\\.]+>,\\s/i', '', $line); } if (false == in_array($line, $translators)) { $translators[] = $line; } } fclose($f); } } foreach ($translators as $translator) { $t = new \stdClass(); $t->translator = $translator; $langInfo->translators[] = $t; } $list[] = $langInfo; } return $list; }
/** * Process language files for a domain. * * @param string $extension Extension name. * @param string $domain Extension domain. * @param boolean $templates If templates should be exported. * * @throws \DomainException * @return $this * * @since 1.0 */ protected function processDomain($extension, $domain, $templates) { $domainBase = trim(str_replace(JPATH_ROOT, '', g11nExtensionHelper::getDomainPath($domain)), '/'); $g11nPath = g11nExtensionHelper::$langDirName; $filesystem = new Filesystem(new Local($this->exportDir . '/' . $domainBase . '/' . $extension . '/' . $g11nPath)); $this->out(sprintf('Processing %s %s:... ', $domain, $extension), false); // Process language templates if ($templates) { $this->out('templates... ', false); $path = g11nStorage::getTemplatePath($extension, $domain); $contents = (new Filesystem(new Local(dirname($path))))->read(basename($path)); if (false == $filesystem->put('templates/' . basename($path), $contents)) { throw new \DomainException('Can not write the file at: ' . $path); } } // Process language files foreach ($this->languages as $lang) { if ('en-GB' == $lang) { continue; } $this->out($lang . '... ', false); $path = g11nExtensionHelper::findLanguageFile($lang, $extension, $domain); if (!$path) { $this->out('<error> ' . $lang . ' NOT FOUND </error>... ', false); continue; } $contents = (new Filesystem(new Local(dirname($path))))->read(basename($path)); if (false == $filesystem->put($lang . '/' . basename($path), $contents)) { throw new \DomainException('Can not write the file: ' . basename($path)); } } $this->out('ok'); return $this; }
/** * Process language files for a domain. * * @param string $extension Extension name. * @param string $domain Extension domain. * @param string $lang Language tag e.g. en-GB or de-DE. * * @return $this * * @since 1.0 * @throws \Exception */ protected function processDomain($extension, $domain, $lang) { $this->out(sprintf('Processing: %1$s %2$s %3$s', $domain, $extension, $lang)); $languageFile = ExtensionHelper::findLanguageFile($lang, $extension, $domain); $templateFile = Storage::getTemplatePath($extension, $domain); // Check if the language file has UNIX style line endings. if ("\n" != PHP_CodeSniffer_File::detectLineEndings($templateFile)) { $this->out($templateFile)->out('<error> The file does not have UNIX style line endings ! </error>')->out(); return $this; } if (false == $languageFile) { $this->out('Creating language file...'); $scopePath = ExtensionHelper::getDomainPath($domain); $extensionPath = ExtensionHelper::getExtensionLanguagePath($extension); $path = $scopePath . '/' . $extensionPath . '/' . $lang; if (!is_dir($path)) { if (!mkdir($path, 0755, true)) { throw new \Exception('Can not create the language folder'); } } $fileName = $lang . '.' . $extension . '.po'; $options = array(); $options[] = 'input=' . $templateFile; $options[] = 'output=' . $path . '/' . $fileName; $options[] = 'no-wrap'; $options[] = 'locale=' . $lang; $cmd = 'msginit --' . implode(' --', $options) . ' 2>&1'; $this->debugOut($cmd); ob_start(); system($cmd); $msg = ob_get_clean(); if (!file_exists($templateFile)) { throw new \Exception('Can not create the language file'); } $this->out('The language file has been created')->out($msg); } else { $this->out('Updating language file...'); $options = array(); $options[] = 'update'; $options[] = 'backup=off'; $options[] = 'no-fuzzy-matching'; $options[] = 'verbose'; $options[] = 'no-wrap'; $paths = array(); $paths[] = $languageFile; $paths[] = $templateFile; $cmd = 'msgmerge --' . implode(' --', $options) . ' "' . implode('" "', $paths) . '"' . ' 2>&1'; $this->debugOut($cmd); ob_start(); system($cmd); $msg = ob_get_clean(); if ($msg) { $this->out($msg); } } return $this; }