Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelperSet()->get('dialog');
     $command = $this->getApplication()->find('translations:fetch');
     $arguments = array('command' => 'translations:fetch', '--username' => $input->getOption('username'), '--password' => $input->getOption('password'), '--keep-english' => true);
     $inputObject = new ArrayInput($arguments);
     $inputObject->setInteractive($input->isInteractive());
     $command->run($inputObject, $output);
     $englishFromOTrance = FetchFromOTrance::getDownloadPath() . DIRECTORY_SEPARATOR . 'en.json';
     if (!file_exists($englishFromOTrance)) {
         $output->writeln("English file from oTrance missing. Aborting");
         return;
     }
     $englishFromOTrance = json_decode(file_get_contents($englishFromOTrance), true);
     Translate::reloadLanguage('en');
     $availableTranslations = $GLOBALS['Piwik_translations'];
     $categories = array_unique(array_merge(array_keys($englishFromOTrance), array_keys($availableTranslations)));
     sort($categories);
     $unnecessary = $outdated = $missing = array();
     foreach ($categories as $category) {
         if (!empty($englishFromOTrance[$category])) {
             foreach ($englishFromOTrance[$category] as $key => $value) {
                 if (!array_key_exists($category, $availableTranslations) || !array_key_exists($key, $availableTranslations[$category])) {
                     $unnecessary[] = sprintf('%s_%s', $category, $key);
                     continue;
                 } else {
                     if (html_entity_decode($availableTranslations[$category][$key]) != html_entity_decode($englishFromOTrance[$category][$key])) {
                         $outdated[] = sprintf('%s_%s', $category, $key);
                         continue;
                     }
                 }
             }
         }
         if (!empty($availableTranslations[$category])) {
             foreach ($availableTranslations[$category] as $key => $value) {
                 if (!array_key_exists($category, $englishFromOTrance) || !array_key_exists($key, $englishFromOTrance[$category])) {
                     $missing[] = sprintf('%s_%s', $category, $key);
                     continue;
                 }
             }
         }
     }
     $output->writeln("");
     if (!empty($missing)) {
         $output->writeln("<bg=yellow;options=bold>-- Following keys are missing on oTrance --</bg=yellow;options=bold>");
         $output->writeln(implode("\n", $missing));
         $output->writeln("");
     }
     if (!empty($unnecessary)) {
         $output->writeln("<bg=yellow;options=bold>-- Following keys might be unnecessary on oTrance --</bg=yellow;options=bold>");
         $output->writeln(implode("\n", $unnecessary));
         $output->writeln("");
     }
     if (!empty($outdated)) {
         $output->writeln("<bg=yellow;options=bold>-- Following keys are outdated on oTrance --</bg=yellow;options=bold>");
         $output->writeln(implode("\n", $outdated));
         $output->writeln("");
     }
     $output->writeln("Finished.");
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelperSet()->get('dialog');
     $command = $this->getApplication()->find('translations:fetch');
     $arguments = array('command' => 'translations:fetch', '--username' => $input->getOption('username'), '--password' => $input->getOption('password'));
     $inputObject = new ArrayInput($arguments);
     $inputObject->setInteractive($input->isInteractive());
     $command->run($inputObject, $output);
     $languages = API::getInstance()->getAvailableLanguageNames();
     $languageCodes = array();
     foreach ($languages as $languageInfo) {
         $languageCodes[] = $languageInfo['code'];
     }
     $plugin = $input->getOption('plugin');
     $files = _glob(FetchFromOTrance::getDownloadPath() . DIRECTORY_SEPARATOR . '*.json');
     $output->writeln("Starting to import new language files");
     if (!$input->isInteractive()) {
         $output->writeln("(!) Non interactive mode: New languages will be skipped");
     }
     $progress = $this->getHelperSet()->get('progress');
     $progress->start($output, count($files));
     foreach ($files as $filename) {
         $progress->advance();
         $code = basename($filename, '.json');
         if (!in_array($code, $languageCodes)) {
             if (!empty($plugin)) {
                 continue;
                 # never create a new language for plugin only
             }
             $createNewFile = false;
             if ($input->isInteractive()) {
                 $createNewFile = $dialog->askConfirmation($output, "\nLanguage {$code} does not exist. Should it be added? ", false);
             }
             if (!$createNewFile) {
                 continue;
                 # do not create a new file for the language
             }
             @touch(PIWIK_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . $code . '.json');
             API::unsetInstance();
             // unset language manager instance, so valid names are refetched
         }
         $command = $this->getApplication()->find('translations:set');
         $arguments = array('command' => 'translations:set', '--code' => $code, '--file' => $filename, '--plugin' => $plugin);
         $inputObject = new ArrayInput($arguments);
         $inputObject->setInteractive($input->isInteractive());
         $command->run($inputObject, new NullOutput());
         // update core modules that aren't in their own repo
         if (empty($plugin)) {
             foreach (self::getPluginsInCore() as $pluginName) {
                 // update translation files
                 $command = $this->getApplication()->find('translations:set');
                 $arguments = array('command' => 'translations:set', '--code' => $code, '--file' => $filename, '--plugin' => $pluginName);
                 $inputObject = new ArrayInput($arguments);
                 $inputObject->setInteractive($input->isInteractive());
                 $command->run($inputObject, new NullOutput());
             }
         }
     }
     $progress->finish();
     $output->writeln("Finished.");
 }