Пример #1
0
 /**
  * Execute the command.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function execute()
 {
     $this->getApplication()->outputTitle('Clear g11n cache dir');
     $this->logOut(sprintf('Cleaning the cache dir in "%s"', ExtensionHelper::getCacheDir()));
     g11n::cleanCache();
     $this->out()->out('The g11n cache directory has been cleared.');
 }
Пример #2
0
 /**
  * Execute the controller.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function execute()
 {
     $application = $this->getContainer()->get('app');
     try {
         g11n::cleanCache();
         $application->enqueueMessage(g11n3t('The cache has been cleared.'), 'success');
     } catch (\Exception $e) {
         $application->enqueueMessage($e->getMessage(), 'error');
     }
     $application->redirect('/');
 }
Пример #3
0
 /**
  * Get a language object.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  */
 protected function loadLanguage()
 {
     // Get the language tag from user input.
     $lang = $this->input->get('lang');
     if ($lang) {
         if (false == in_array($lang, $this->get('languages'))) {
             // Unknown language from user input - fall back to default
             $lang = g11n::getDefault();
         }
         if (false == in_array($lang, $this->get('languages'))) {
             // Unknown default language - Fall back to British.
             $lang = 'en-GB';
         }
         // Store the language tag.
         $this->getSession()->set('lang', $lang);
         $this->getUser()->params->set('language', $lang);
     } else {
         // Get the language tag from the user params or session. Default to British.
         $lang = $this->getUser()->params->get('language', $this->getSession()->get('lang', 'en-GB'));
     }
     if ($lang) {
         // Set the current language if anything has been found.
         g11n::setCurrent($lang);
     }
     // Set language debugging.
     g11n::setDebug($this->get('debug.language'));
     // Set the language cache directory.
     if ('vagrant' == getenv('JTRACKER_ENVIRONMENT')) {
         g11n::setCacheDir('/tmp');
     } else {
         g11n::setCacheDir(JPATH_ROOT . '/cache');
     }
     // Load the core language file.
     g11n::addDomainPath('Core', JPATH_ROOT . '/src');
     g11n::loadLanguage('JTracker', 'Core');
     // Load template language files.
     g11n::addDomainPath('Template', JPATH_ROOT . '/templates');
     g11n::loadLanguage('JTracker', 'Template');
     // Add the App domain path.
     g11n::addDomainPath('App', JPATH_ROOT . '/src/App');
     if ($this->get('debug.system') || $this->get('debug.database') || $this->get('debug.language')) {
         // Load the Debug App language file.
         g11n::loadLanguage('Debug', 'App');
     }
     return $this;
 }
Пример #4
0
 /**
  * Returns a list of global variables to add to the existing list.
  *
  * @return  array  An array of global variables.
  *
  * @since   1.0
  */
 public function getGlobals()
 {
     /* @type \JTracker\Application $application */
     $application = $this->container->get('app');
     return array('uri' => $application->get('uri'), 'offset' => $application->getUser()->params->get('timezone') ? $application->getUser()->params->get('timezone') : $application->get('system.offset'), 'languages' => $application->get('languages'), 'jdebug' => JDEBUG, 'lang' => $application->getUser()->params->get('language') ? $application->getUser()->params->get('language') : g11n::getCurrent(), 'g11nJavaScript' => g11n::getJavaScript(), 'useCDN' => $application->get('system.use_cdn'));
 }
Пример #5
0
 /**
  * Get info about processed language strings.
  *
  * @return  \stdClass
  *
  * @since   1.0
  */
 protected function getLanguageStringsInfo()
 {
     $items = g11n::get('processedItems');
     $info = new \stdClass();
     $info->total = count($items);
     $info->untranslateds = 0;
     foreach ($items as $item) {
         if ('-' == $item->status) {
             $info->untranslateds++;
         }
     }
     return $info;
 }
Пример #6
0
 /**
  * Load a foreign language.
  *
  * @return  $this
  *
  * @since   1.0
  */
 protected function loadLanguage()
 {
     // Get the language tag from user input.
     $lang = $this->input->get('lang');
     if ($lang) {
         if (false == in_array($lang, $this->get('languages'))) {
             // Unknown language from user input - fall back to default
             $lang = g11n::getDefault();
         }
         if (false == in_array($lang, $this->get('languages'))) {
             // Unknown default language - Fall back to British.
             $lang = 'en-GB';
         }
     } else {
         $lang = g11n::getCurrent();
         if (false == in_array($lang, $this->get('languages'))) {
             // Unknown current language - Fall back to British.
             $lang = 'en-GB';
         }
     }
     if ($lang) {
         // Set the current language if anything has been found.
         g11n::setCurrent($lang);
     }
     // Set language debugging.
     g11n::setDebug($this->get('debug.language'));
     // Set the language cache directory.
     if ('vagrant' == getenv('JTRACKER_ENVIRONMENT')) {
         g11n::setCacheDir('/tmp');
     } else {
         g11n::setCacheDir(JPATH_ROOT . '/cache');
     }
     // Load the CLI language file.
     g11n::addDomainPath('CLI', JPATH_ROOT);
     g11n::loadLanguage('cli', 'CLI');
     return $this;
 }
Пример #7
0
 /**
  * Process config files in XML format.
  *
  * @param   array   $cleanFiles    Source files to process.
  * @param   string  $templatePath  The path to store the template.
  *
  * @return  $this
  *
  * @since   1.0
  * @throws  \Exception
  */
 private function processConfigFiles($cleanFiles, $templatePath)
 {
     defined('NL') || define('NL', "\n");
     $parser = g11n::getCodeParser('xml');
     $potParser = g11n::getLanguageParser('pot');
     $options = new \stdClass();
     $outFile = new FileInfo();
     foreach ($cleanFiles as $fileName) {
         $fileInfo = $parser->parse($fileName);
         if (!count($fileInfo->strings)) {
             continue;
         }
         $relPath = str_replace(JPATH_ROOT . DS, '', $fileName);
         foreach ($fileInfo->strings as $key => $strings) {
             foreach ($strings as $string) {
                 if (array_key_exists($string, $outFile->strings)) {
                     if (strpos($outFile->strings[$string]->info, $relPath . ':' . $key) !== false) {
                         continue;
                     }
                     $outFile->strings[$string]->info .= '#: ' . $relPath . ':' . $key . NL;
                     continue;
                 }
                 $t = new TransInfo();
                 $t->info .= '#: ' . $relPath . ':' . $key . NL;
                 $outFile->strings[$string] = $t;
             }
         }
     }
     $buffer = $potParser->generate($outFile, $options);
     if (!file_put_contents($templatePath, $buffer)) {
         throw new \Exception('Unable to write the output file');
     }
     return $this;
 }