Skip to content

Commit

Permalink
Remove output_options. Use the dumper parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
fchris82 committed Feb 27, 2018
1 parent cdc1391 commit 6f460bc
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 92 deletions.
10 changes: 0 additions & 10 deletions Command/ExtractTranslationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ protected function configure()
->addOption('default-output-format', null, InputOption::VALUE_REQUIRED, 'The default output format (defaults to xlf).')
->addOption('keep', null, InputOption::VALUE_NONE, 'Define if the updater service should keep the old translation (defaults to false).')
->addOption('external-translations-dir', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Load external translation resources')
->addOption('add-date', null, InputOption::VALUE_REQUIRED, 'Whether to add the extraction date to the extracted xlf file e.g. --add-date=0')
->addOption('add-filerefs', null, InputOption::VALUE_REQUIRED, 'Whether to add JMS file references as extradata to the extracted xlf file e.g. --add-filerefs=1')
;
}

Expand Down Expand Up @@ -253,13 +251,5 @@ private function updateWithInput(InputInterface $input, ConfigBuilder $builder)
if ($loadResource = $input->getOption('external-translations-dir')) {
$builder->setLoadResources($loadResource);
}

if ($addDate = $input->getOption('add-date')) {
$builder->setOutputOption('xlf', 'add_date', (boolean) $addDate);
}

if ($addFileRefs = $input->getOption('add-filerefs')) {
$builder->setOutputOption('xlf', 'add_filerefs', (boolean) $addFileRefs);
}
}
}
16 changes: 0 additions & 16 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,6 @@ public function getConfigTreeBuilder()
->end()
->scalarNode('output_dir')->isRequired()->cannotBeEmpty()->end()
->scalarNode('keep')->defaultValue(false)->end()
->arrayNode('output_options')
->children()
->arrayNode('xlf')
->children()
->booleanNode('add_date')->defaultTrue()->end()
->booleanNode('add_filerefs')->defaultTrue()->end()
->end()
->end()
->arrayNode('xliff')
->children()
->booleanNode('add_date')->defaultTrue()->end()
->booleanNode('add_filerefs')->defaultTrue()->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
Expand Down
6 changes: 0 additions & 6 deletions DependencyInjection/JMSTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ public function load(array $configs, ContainerBuilder $container)
$def->addMethodCall('setLoadResources', array($extractConfig['external_translations_dirs']));
}

if (isset($extractConfig['output_options'])) {
foreach ($extractConfig['output_options'] as $format => $formatOptions) {
$def->addMethodCall('setOutputOptions', array($format, $formatOptions));
}
}

$requests[$name] = $def;
}

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Differences:
- Collect the placeholders (`<jms:placeholder>` element)
- Move meaning to `jms:meaning` attribute
- Custom translated form fields
- Add new configurations: `output_options` -> `add_date` and `add_filerefs`
- Handle `addViolation()`, `addViolationAt()` and `buildViolation()` functions
- Add new Annotation: `AltTrans` . You can add basic translations:

Expand Down
2 changes: 1 addition & 1 deletion Tests/Translation/FileWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testCatalogueIsSortedBeforeBeingDumped()

$path = tempnam(sys_get_temp_dir(), 'filewriter');

$writer->write($catalogue, 'messages', $path, 'test', []);
$writer->write($catalogue, 'messages', $path, 'test');
@unlink($path);
}
}
17 changes: 1 addition & 16 deletions Translation/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ final class Config
*/
private $loadResources;

/**
* @var array
*/
private $outputOptions;

/**
* Config constructor.
* @param $translationsDir
Expand All @@ -109,9 +104,8 @@ final class Config
* @param array $enabledExtractors
* @param bool $keepOldMessages
* @param array $loadResources
* @param array $outputOptions
*/
public function __construct($translationsDir, $locale, array $ignoredDomains, array $domains, $outputFormat, $defaultOutputFormat, array $scanDirs, array $excludedDirs, array $excludedNames, array $enabledExtractors, $keepOldMessages, array $loadResources, array $outputOptions)
public function __construct($translationsDir, $locale, array $ignoredDomains, array $domains, $outputFormat, $defaultOutputFormat, array $scanDirs, array $excludedDirs, array $excludedNames, array $enabledExtractors, $keepOldMessages, array $loadResources)
{
if (empty($translationsDir)) {
throw new InvalidArgumentException('The directory where translations are must be set.');
Expand Down Expand Up @@ -151,7 +145,6 @@ public function __construct($translationsDir, $locale, array $ignoredDomains, ar
$this->enabledExtractors = $enabledExtractors;
$this->keepOldMessages = $keepOldMessages;
$this->loadResources = $loadResources;
$this->outputOptions = $outputOptions;
}

/**
Expand Down Expand Up @@ -275,12 +268,4 @@ public function getLoadResources()
{
return $this->loadResources;
}

/**
* @return array
*/
public function getOutputOptions($format = null)
{
return $format && isset($this->outputOptions[$format]) ? $this->outputOptions[$format] : $this->outputOptions;
}
}
27 changes: 1 addition & 26 deletions Translation/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ final class ConfigBuilder
*/
private $loadResources = array();

/**
* @var array
*/
private $outputOptions = [
'xlf' => [
'add_date' => true,
'add_filerefs' => true
]
];

/**
* @static
* @param Config $config
Expand Down Expand Up @@ -312,8 +302,7 @@ public function getConfig()
$this->excludedNames,
$this->enabledExtractors,
$this->keepOldTranslations,
$this->loadResources,
$this->outputOptions
$this->loadResources
);
}

Expand All @@ -327,18 +316,4 @@ public function setLoadResources(array $loadResources)

return $this;
}

public function setOutputOptions($format, array $options)
{
$this->outputOptions[$format] = $options;

return $this;
}

public function setOutputOption($format, $key, $value)
{
$this->outputOptions[$format][$key] = $value;

return $this;
}
}
12 changes: 1 addition & 11 deletions Translation/FileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ public function __construct(array $dumpers = array())
* @param string $domain
* @param string $filePath
* @param string $format
* @param array $outputOptions
* @throws \JMS\TranslationBundle\Exception\InvalidArgumentException
*/
public function write(MessageCatalogue $catalogue, $domain, $filePath, $format, $outputOptions)
public function write(MessageCatalogue $catalogue, $domain, $filePath, $format)
{
if (!isset($this->dumpers[$format])) {
$allowedFormats = array_keys($this->dumpers);
Expand All @@ -65,15 +64,6 @@ public function write(MessageCatalogue $catalogue, $domain, $filePath, $format,

$dumper = $this->dumpers[$format];

if ($dumper instanceof \JMS\TranslationBundle\Translation\Dumper\XliffDumper) {
if (isset($outputOptions['add_date'])) {
$dumper->setAddDate($outputOptions['add_date']);
}
if (isset($outputOptions['add_filerefs'])) {
$dumper->setAddReference($outputOptions['add_filerefs']);
}
}

file_put_contents($filePath, $dumper->dump($catalogue, $domain, $filePath));
}
}
7 changes: 2 additions & 5 deletions Translation/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ public function updateTranslation($file, $format, $domain, $locale, $id, $trans)
->setNew(false)
;

$outputOptions = $this->config['output_options'][$format];

$this->writer->write($catalogue, $domain, $file, $format, $outputOptions);
$this->writer->write($catalogue, $domain, $file, $format);
}

/**
Expand Down Expand Up @@ -171,9 +169,8 @@ public function process(Config $config)
}

$outputFile = $this->config->getTranslationsDir().'/'.$name.'.'.$this->config->getLocale().'.'.$format;
$outputOptions = $this->config->getOutputOptions($format);
$this->logger->info(sprintf('Writing translation file "%s".', $outputFile));
$this->writer->write($scannedCatalogue, $name, $outputFile, $format, $outputOptions);
$this->writer->write($scannedCatalogue, $name, $outputFile, $format);
}
}

Expand Down

0 comments on commit 6f460bc

Please sign in to comment.