Skip to content

Commit dbc856d

Browse files
committed
feature #21578 [Translation] Added a lint:xliff command for XLIFF files (javiereguiluz)
This PR was squashed before being merged into the 3.3-dev branch (closes #21578). Discussion ---------- [Translation] Added a lint:xliff command for XLIFF files | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19942 | License | MIT | Doc PR | - It works exactly the same as the `lint:yaml` command: ### Lint a single file ![single-file](https://cloud.githubusercontent.com/assets/73419/22821214/6b459454-ef7a-11e6-9320-029c22ab8803.png) ### Lint a bundle ![bundle](https://cloud.githubusercontent.com/assets/73419/22821215/6c2c0196-ef7a-11e6-9de0-a1816eede9b3.png) ### Get the result in JSON ![json](https://cloud.githubusercontent.com/assets/73419/22829844/bacaa68e-efa4-11e6-9341-0c3d4821c5c7.png) Commits ------- 7609e440ff [Translation] Added a lint:xliff command for XLIFF files
2 parents 0474277 + b502bb0 commit dbc856d

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

Command/XliffLintCommand.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Command;
13+
14+
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Translation\Command\XliffLintCommand as BaseLintCommand;
18+
19+
/**
20+
* Validates XLIFF files syntax and outputs encountered errors.
21+
*
22+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
23+
* @author Robin Chalas <robin.chalas@gmail.com>
24+
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
25+
*/
26+
class XliffLintCommand extends Command
27+
{
28+
private $command;
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
protected function configure()
34+
{
35+
$this->setName('lint:xliff');
36+
37+
if (!$this->isEnabled()) {
38+
return;
39+
}
40+
41+
$directoryIteratorProvider = function ($directory, $default) {
42+
if (!is_dir($directory)) {
43+
$directory = $this->getApplication()->getKernel()->locateResource($directory);
44+
}
45+
46+
return $default($directory);
47+
};
48+
49+
$isReadableProvider = function ($fileOrDirectory, $default) {
50+
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
51+
};
52+
53+
$this->command = new BaseLintCommand(null, $directoryIteratorProvider, $isReadableProvider);
54+
55+
$this
56+
->setDescription($this->command->getDescription())
57+
->setDefinition($this->command->getDefinition())
58+
->setHelp($this->command->getHelp().<<<'EOF'
59+
60+
Or find all files in a bundle:
61+
62+
<info>php %command.full_name% @AcmeDemoBundle</info>
63+
64+
EOF
65+
);
66+
}
67+
68+
/**
69+
* {@inheritdoc}
70+
*/
71+
public function isEnabled()
72+
{
73+
return class_exists(BaseLintCommand::class);
74+
}
75+
76+
protected function execute(InputInterface $input, OutputInterface $output)
77+
{
78+
return $this->command->execute($input, $output);
79+
}
80+
}

0 commit comments

Comments
 (0)