/**
  * test all languages
  *
  * @group Plugins
  *
  * @dataProvider getTestDataForLanguageFiles
  */
 function testGetTranslationsForLanguages($language, $plugin)
 {
     $translationWriter = new Writer($language, $plugin);
     $baseTranslations = $translationWriter->getTranslations('en');
     $translationWriter->addValidator(new NoScripts());
     if (empty($plugin)) {
         $translationWriter->addValidator(new CoreTranslations($baseTranslations));
     }
     // prevent build from failing when translations string have been deleted
     //        $translationWriter->addFilter(new ByBaseTranslations($baseTranslations));
     $translationWriter->addFilter(new EmptyTranslations());
     $translationWriter->addFilter(new ByParameterCount($baseTranslations));
     $translationWriter->addFilter(new UnnecassaryWhitespaces($baseTranslations));
     $translationWriter->addFilter(new EncodedEntities());
     $translations = $translationWriter->getTranslations($language);
     if (empty($translations)) {
         return;
         // skip language / plugin combinations that aren't present
     }
     $translationWriter->setTranslations($translations);
     $this->assertTrue($translationWriter->isValid(), $translationWriter->getValidationMessage());
     if ($translationWriter->wasFiltered()) {
         $translationWriter->saveTemporary();
         $this->fail(implode("\n", $translationWriter->getFilterMessages()) . "\n" . 'Translation file errors detected in ' . $language . "...\n" . "To overwrite you could manually fix the language files, or run the following command may work if you have access to oTrance: \n" . "\$ ./console translations:update [--plugin=XYZ] \n");
     }
 }
Exemplo n.º 2
0
 /**
  * @group Core
  *
  * @dataProvider getInvalidTranslations
  */
 public function testSetTranslationsInvalid($translations, $error)
 {
     $writer = new Writer('de');
     $writer->setTranslations($translations);
     $writer->addValidator(new NoScripts());
     $writer->addValidator(new CoreTranslations());
     $this->assertFalse($writer->isValid());
     $this->assertEquals($error, $writer->getValidationMessage());
 }
Exemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelperSet()->get('dialog');
     $languageCode = $input->getOption('code');
     $filename = $input->getOption('file');
     $languageCodes = API::getInstance()->getAvailableLanguages();
     if (empty($languageCode) || !in_array($languageCode, $languageCodes)) {
         $languageCode = $dialog->askAndValidate($output, 'Please provide a valid language code: ', function ($code) use($languageCodes) {
             if (!in_array($code, array_values($languageCodes))) {
                 throw new \InvalidArgumentException(sprintf('Language code "%s" is invalid.', $code));
             }
             return $code;
         });
     }
     if (empty($filename) || !file_exists($filename)) {
         $filename = $dialog->askAndValidate($output, 'Please provide a file to load translations from: ', function ($file) {
             if (!file_exists($file)) {
                 throw new \InvalidArgumentException(sprintf('File "%s" does not exist.', $file));
             }
             return $file;
         });
     }
     $output->writeln("Starting to import data from '{$filename}' to language '{$languageCode}'");
     $plugin = $input->getOption('plugin');
     $translationWriter = new Writer($languageCode, $plugin);
     $baseTranslations = $translationWriter->getTranslations("en");
     $translationWriter->addValidator(new NoScripts());
     if (empty($plugin)) {
         $translationWriter->addValidator(new CoreTranslations($baseTranslations));
     }
     $translationWriter->addFilter(new ByBaseTranslations($baseTranslations));
     $translationWriter->addFilter(new EmptyTranslations());
     $translationWriter->addFilter(new ByParameterCount($baseTranslations));
     $translationWriter->addFilter(new UnnecassaryWhitespaces($baseTranslations));
     $translationWriter->addFilter(new EncodedEntities());
     $translationData = file_get_contents($filename);
     $translations = json_decode($translationData, true);
     $translationWriter->setTranslations($translations);
     if (!$translationWriter->isValid()) {
         $output->writeln("Failed setting translations:" . $translationWriter->getValidationMessage());
         return;
     }
     if (!$translationWriter->hasTranslations()) {
         $output->writeln("No translations available");
         return;
     }
     $translationWriter->save();
     $output->writeln("Finished.");
 }