Skip to content

[Translation] Added a lint:xliff command for XLIFF files #21578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

javiereguiluz
Copy link
Member

@javiereguiluz javiereguiluz commented Feb 10, 2017

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

Lint a bundle

bundle

Get the result in JSON

json

if (-1 === $error->line) {
$errorMessages[] = $error->message;
} else {
$errorMessages[] = sprintf('Line %d, Column %d: %s', $error->line, $error->column, trim($error->message));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in JSON, it may be better to have the line and column as separate properties: { line: 10, column: 5, message: "unexpected char"}.
It would make the output more useful by allowing to known the location without parsing the error message.

you could do it by building such an array here, and doing the sprintf only in displayTxt. In this case, I would keep the same structure for general errors, but with null for the line and column.

Copy link
Member

@chalasr chalasr Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be interesting to port this change on other lint commands for consistency (yaml, twig)

*/
public function isEnabled()
{
return class_exists(BaseLintCommand::class) && parent::isEnabled();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the parent logic is just return true, so it is not really necessary.

@javiereguiluz
Copy link
Member Author

Note: I've called this command lint:translation instead of lint:xliff or lint:xlf because, in the future, the idea would be to keep adding linting features related to translation ... and maybe not directly related to XLIFF.

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Feb 11, 2017
@nicolas-grekas
Copy link
Member

do we have any plan for other formats? if not, I'm not sure about the name.
"linting" is about some specific language - so having the name of the actual linted language in the command looks good to me.

@javiereguiluz javiereguiluz changed the title [Translation] Added a lint:translation command for XLIFF files [Translation] Added a lint:xliff command for XLIFF files Feb 12, 2017
Copy link
Contributor

@phansys phansys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status: Needs work.

$io->text('<error> ERROR </error>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
$io->listing(array_map(function ($error) {
// general document errors have a '-1' line number
return -1 === $error['line'] ? $error['message'] : sprintf('Line %d, Column %d: %s', $error['line'], $error['column'], $error['message']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If "-1" will be not allowed as line number, "%u" is more suitable as type specifier. The same applies for column.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, the -1 value is not used ... but this could change at any moment, so let's keep it safe with the %d syntax.

}
}

if ($erroredFiles === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use Yoda condition.

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thank you for this PR. I like it and it sure is needed.

I have briefly reviewed the code and I have run tests on my application.

May I ask you to extract the validate function to a separate class? That would make it easier for third party libraries to re-use the validation logic.

@javiereguiluz
Copy link
Member Author

Thanks for the reviews. About extracting the validate() method:

  • It's not the common practice in the other linters
  • For interoperability, the idea would be to execute lint:xliff --format=json
  • However, I'd love if linters would be easier to use (for example like this -> [Yaml] Add bin/lint for using the LintCommand #19916 which sadly was refused)

So ... I don't know what to do.

@fabpot
Copy link
Member

fabpot commented Feb 18, 2017

Thank you @javiereguiluz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants