Beispiel #1
0
 /**
  * Fetch translations.
  *
  * @return  $this
  *
  * @since   1.0
  */
 private function fetchTranslations()
 {
     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);
     defined('JDEBUG') || define('JDEBUG', 0);
     // Process CLI files
     $this->receiveFiles('cli', 'CLI');
     // Process core files
     $this->receiveFiles('JTracker', 'Core');
     // Process core JS files
     $this->receiveFiles('JTracker.js', 'CoreJS');
     // Process template files
     $this->receiveFiles('JTracker', 'Template');
     // Process app files
     /* @type \DirectoryIterator $fileInfo */
     foreach (new \DirectoryIterator(JPATH_ROOT . '/src/App') as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         $this->receiveFiles($fileInfo->getFileName(), 'App');
     }
     return $this;
 }
Beispiel #2
0
 /**
  * Create list of files to export.
  *
  * @return $this
  *
  * @since   1.0
  */
 private function exportFiles()
 {
     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());
     $templates = $this->getApplication()->input->getCmd('templates');
     foreach ($scopes as $domain => $extensions) {
         foreach ($extensions as $extension) {
             $this->processDomain($extension, $domain, $templates);
         }
     }
     return $this;
 }
Beispiel #3
0
 /**
  * Execute the command.
  *
  * @return  void
  *
  * @since   1.0
  * @throws  \Exception
  */
 public function execute()
 {
     $this->getApplication()->outputTitle('Make Language files');
     ExtensionHelper::addDomainPath('Core', JPATH_ROOT . '/src');
     ExtensionHelper::addDomainPath('Template', JPATH_ROOT . '/templates');
     ExtensionHelper::addDomainPath('App', JPATH_ROOT . '/src/App');
     ExtensionHelper::addDomainPath('CLI', JPATH_ROOT);
     $languages = $this->getApplication()->get('languages');
     $reqExtension = $this->getApplication()->input->getCmd('extension');
     // Process the CLI application
     if (!$reqExtension || $reqExtension == 'cli') {
         $extension = 'cli';
         $domain = 'CLI';
         $this->out('Processing: ' . $domain . ' ' . $extension);
         foreach ($languages as $lang) {
             if ('en-GB' == $lang) {
                 continue;
             }
             $this->processDomain($extension, 'CLI', $lang);
         }
     }
     // Process JTracker core
     if (!$reqExtension || $reqExtension == 'JTracker') {
         foreach ($languages as $lang) {
             if ('en-GB' == $lang) {
                 continue;
             }
             $this->processDomain('JTracker', 'Core', $lang)->processDomain('JTracker.js', 'Core', $lang)->processDomain('JTracker', 'Template', $lang);
         }
     }
     // 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);
         foreach ($languages as $lang) {
             if ('en-GB' == $lang) {
                 continue;
             }
             $this->processDomain($extension, 'App', $lang);
         }
     }
     $this->out()->out('Finished =;)');
 }
Beispiel #4
0
 /**
  * Execute the command.
  *
  * @return  integer
  *
  * @since   1.0
  * @throws  \UnexpectedValueException
  */
 public function execute()
 {
     $this->getApplication()->outputTitle('Check language files');
     ExtensionHelper::addDomainPath('Core', JPATH_ROOT . '/src');
     ExtensionHelper::addDomainPath('Template', JPATH_ROOT . '/templates');
     ExtensionHelper::addDomainPath('App', JPATH_ROOT . '/src/App');
     $scopes = array('Core' => array('JTracker', 'JTracker.js'), 'Template' => array('JTracker'), 'App' => (new Filesystem(new Local(JPATH_ROOT . '/src/App')))->listPaths());
     $languages = $this->getApplication()->get('languages');
     $languages[] = 'templates';
     $errors = false;
     foreach ($scopes as $domain => $extensions) {
         foreach ($extensions as $extension) {
             $scopePath = ExtensionHelper::getDomainPath($domain);
             $extensionPath = ExtensionHelper::getExtensionLanguagePath($extension);
             foreach ($languages as $language) {
                 $path = $scopePath . '/' . $extensionPath . '/' . $language;
                 $path .= 'templates' == $language ? '/' . $extension . '.pot' : '/' . $language . '.' . $extension . '.po';
                 $this->debugOut(sprintf('Check: %s-%s %s in %s', $domain, $extension, $language, $path));
                 if (false == file_exists($path)) {
                     $this->debugOut('not found');
                     continue;
                 }
                 // Check if the language file has UNIX style line endings.
                 if ("\n" != PHP_CodeSniffer_File::detectLineEndings($path)) {
                     $this->out($path)->out('<error> The file does not have UNIX style line endings ! </error>')->out();
                     continue;
                 }
                 // Check the language file for errors.
                 $output = shell_exec('msgfmt -c ' . $path . ' 2>&1');
                 if ($output) {
                     // If the command produces any output, that means errors.
                     $errors = true;
                     $this->out($output);
                 } else {
                     $this->debugOut('ok');
                 }
             }
         }
     }
     $this->out($errors ? '<error> There have been errors. </error>' : '<ok>Language file syntax OK</ok>');
     if ($this->exit) {
         exit($errors ? 1 : 0);
     }
     return $errors ? 1 : 0;
 }
Beispiel #5
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;
 }
Beispiel #6
0
 /**
  * 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;
 }
Beispiel #7
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);
     }
 }