Exemplo n.º 1
0
 /**
  * Push translations.
  *
  * @return  $this
  *
  * @throws \DomainException
  * @since   1.0
  */
 private function uploadTemplates()
 {
     $transifexProject = $this->getApplication()->get('transifex.project');
     $create = $this->getApplication()->input->get('create');
     defined('JDEBUG') || define('JDEBUG', 0);
     ExtensionHelper::addDomainPath('Core', JPATH_ROOT . '/src');
     ExtensionHelper::addDomainPath('CoreJS', JPATH_ROOT . '/src');
     ExtensionHelper::addDomainPath('Template', JPATH_ROOT . '/templates');
     ExtensionHelper::addDomainPath('App', JPATH_ROOT . '/src/App');
     ExtensionHelper::addDomainPath('CLI', JPATH_ROOT);
     $scopes = ['Core' => ['JTracker'], 'CoreJS' => ['JTracker.js'], 'Template' => ['JTracker'], 'CLI' => ['cli'], 'App' => (new Filesystem(new Local(JPATH_ROOT . '/src/App')))->listPaths()];
     foreach ($scopes as $domain => $extensions) {
         foreach ($extensions as $extension) {
             $name = $extension . ' ' . $domain;
             $alias = OutputFilter::stringURLUnicodeSlug($name);
             $this->out('Processing: ' . $name . ' - ' . $alias);
             $templatePath = Storage::getTemplatePath($extension, $domain);
             if (false == file_exists($templatePath)) {
                 throw new \DomainException(sprintf('Language template for %s not found.', $name));
             }
             $this->out($templatePath);
             try {
                 if ($create) {
                     $this->transifex->resources->createResource($transifexProject, $name, $alias, 'PO', ['file' => $templatePath]);
                     $this->out('<ok>Resource created successfully</ok>');
                 } else {
                     $this->transifex->resources->updateResourceContent($transifexProject, $alias, $templatePath, 'file');
                     $this->out('<ok>Resource updated successfully</ok>');
                 }
             } catch (\Exception $e) {
                 $this->out('<error>' . $e->getMessage() . '</error>');
             }
             $this->out();
         }
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * Execute the command.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function execute()
 {
     $this->getApplication()->outputTitle('Make Language templates');
     ExtensionHelper::addDomainPath('Core', JPATH_ROOT . '/src');
     ExtensionHelper::addDomainPath('CoreJS', JPATH_ROOT . '/www/jtracker');
     ExtensionHelper::addDomainPath('Template', JPATH_ROOT . '/cache/twig');
     ExtensionHelper::addDomainPath('App', JPATH_ROOT . '/cache/twig');
     ExtensionHelper::addDomainPath('CLI', JPATH_ROOT);
     defined('JDEBUG') || define('JDEBUG', 0);
     $reqExtension = $this->getApplication()->input->getCmd('extension');
     // Cleanup
     $this->delTree(JPATH_ROOT . '/cache/twig');
     if (!$reqExtension || $reqExtension == 'JTracker') {
         // Process core files
         $extension = 'JTracker';
         $domain = 'Core';
         $this->out('Processing: ' . $domain . ' ' . $extension);
         $templatePath = Storage::getTemplatePath($extension, $domain);
         $paths = array(ExtensionHelper::getDomainPath($domain));
         $this->processTemplates($extension, $domain, 'php', $paths, $templatePath);
         // Process core JS files
         $extension = 'core.js';
         $domain = 'CoreJS';
         $this->out('Processing: ' . $domain . ' ' . $extension);
         $templatePath = Storage::getTemplatePath('JTracker.js', 'Core');
         $paths = array(ExtensionHelper::getDomainPath($domain));
         $this->processTemplates($extension, $domain, 'js', $paths, $templatePath);
         // Process base template
         $extension = 'JTracker';
         $domain = 'Template';
         $this->out('Processing: ' . $domain . ' ' . $extension);
         $twigDir = JPATH_ROOT . '/cache/twig/JTracker';
         $this->makePhpFromTwig(JPATH_ROOT . '/templates', $twigDir);
         $templatePath = JPATH_ROOT . '/templates/' . $extension . '/' . ExtensionHelper::$langDirName . '/templates/' . $extension . '.pot';
         $paths = array(ExtensionHelper::getDomainPath($domain));
         $this->processTemplates($extension, $domain, 'php', $paths, $templatePath);
         $this->replacePaths(JPATH_ROOT . '/templates', $twigDir, $templatePath);
         // Process the CLI application
         $extension = 'cli';
         $domain = 'CLI';
         $this->out('Processing: ' . $domain . ' ' . $extension);
         $templatePath = Storage::getTemplatePath($extension, $domain);
         $paths = array(ExtensionHelper::getDomainPath($domain));
         $this->processTemplates($extension, $domain, 'php', $paths, $templatePath);
     }
     // Process App templates
     /* @type \DirectoryIterator $fileInfo */
     foreach (new \DirectoryIterator(JPATH_ROOT . '/src/App') as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         $extension = $fileInfo->getFileName();
         if ($reqExtension && $reqExtension != $extension) {
             continue;
         }
         $this->out('Processing App: ' . $extension);
         $domain = 'App';
         $this->makePhpFromTwig(JPATH_ROOT . '/templates/' . strtolower($extension), JPATH_ROOT . '/cache/twig/' . $extension, true);
         $templatePath = JPATH_ROOT . '/src/App/' . $extension . '/' . ExtensionHelper::$langDirName . '/templates/' . $extension . '.pot';
         $paths = array(ExtensionHelper::getDomainPath($domain), JPATH_ROOT . '/src/App');
         $this->processTemplates($extension, $domain, 'php', $paths, $templatePath);
         $this->replacePaths(JPATH_ROOT . '/templates/' . strtolower($extension), JPATH_ROOT . '/cache/twig/' . $extension, $templatePath);
     }
 }