Skip to content

[Translation] Add a new lint:translation command #19942

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
bocharsky-bw opened this issue Sep 15, 2016 · 9 comments
Closed

[Translation] Add a new lint:translation command #19942

bocharsky-bw opened this issue Sep 15, 2016 · 9 comments

Comments

@bocharsky-bw
Copy link
Contributor

Hi, guys!

I'd like to open a PR for implementing a new console command for translations:

# shows the errors in the console
$ ./bin/console lint:translation <file | dir | @BundleName>

# reorders translation messages according to the message order for default locale
$ ./bin/console lint:translation --reorder <file | dir | @BundleName>

# fixes the errors modifying the translation files
$ ./bin/console lint:translation --fix <file | dir | @BundleName>

# fixes the errors modifying the translation files and
# adds empty missing translations from the original file
$ ./bin/console lint:translation --fix --add-missing <file | dir | @BundleName>

First of all, I'd like to say that maintain translations is a difficult process, especially if we want to keep them consistent with each other. I mean: fix syntax, keep message order in sync in different files, add missing translation messages, etc.).

Actually, we can see it in the example of Symfony Demo project though this is a small project. This problem is even more relevant for big projects. Symfony Web Debug Toolbar helps with missed translations, but its tips relate to the opened page only (the page that developer's viewing right now). That's why I want to suggest this new console command.

What do you think about it?

@javiereguiluz
Copy link
Member

I like this idea. But I'd think a bit more about the options of the command. It's common for this kind of commands to have two modes: 1) "show the changes to do but don't make them", 2) "make those changes".

In this example, --fix seems the option that makes changes ... but there is a --reorder option that makes changes too.

The other issue to think about is if we want to allow to select the fixers: reorder, add missing, etc. or we want to run all of them at once.

Finally, I'd like to have a list of proposed fixers. For example:

  • reorder: changes translation files to have their contents in the same order as the original translation file.
  • add missing: changes translation files to add all the translations defined in the original translation files and missing in this particular translation files.
  • ...

@bocharsky-bw
Copy link
Contributor Author

@javiereguiluz I agree with you, it makes sense to make changes for --reorder option only with specified --fix option.

I suppose, we'd like to have some format-specific fixers, for example, for YAML translations:

# inline
post.no_comments: No comments
post.no_posts: No posts
# or expanded
post:
    no_comments: No comments
    no_posts: No posts

I'm also wondering in the best way of original translation determination. I think we should provide --default-locale (or just --locale) option for it which helps to determine original translation file i.e. the file, which will be used as the basis for --reorder, --add-missing, etc. options.

@ro0NL
Copy link
Contributor

ro0NL commented Sep 17, 2016

@bocharsky-bw did you considered translation:update on this? Maybe we should avoid having 2 commands doing write operations..

Ie. extending the update command with --file could work? Point is --add-missing feels like translation:update.

translation:update --reorder --dot-notation --no-add-missing can be considered as we have many options to tweak already.

Last but not least, the command could be moved to the translation component like the yaml:lint command.

@bocharsky-bw
Copy link
Contributor Author

Hey @ro0NL , I think single lint:translation command with a few options will be enough for these purposes. We already have lint:twig and lint:yaml similar commands. BTW, the yaml:lint command is deprecated and doesn't work in Symfony 3, so lint:translation looks like a better name here.

What about formatting YAML translation files: I think doing the same operation with different commands is a bad idea. The command should determine translation file format by itself and process it properly.

@ro0NL
Copy link
Contributor

ro0NL commented Sep 18, 2016

Maybe you're right, and 2 commands could work

  • translation:update updates files based on source
    • functional related -> we need all strings in a file
  • lint:translations updates files based on a template file
    • cosmetic related -> we need to organize our files in a sane way

About (re)formatting; this only affects inline vs. expanded (ie. dot notation yes/no) and is definitely translation related, but only for YAML+PHP. Im more or less leaning to something like LoaderInterface::supportsDotNotation to avoid tracking a list of extensions somewhere.

@rvanlaak
Copy link
Contributor

There are quite some bundles that do a nice job on this, or am I mistaking on the scope of your issue here? ;)

https://github.com/schmittjoh/JMSTranslationBundle
https://github.com/lexik/LexikTranslationBundle

@stof
Copy link
Member

stof commented Sep 21, 2016

A command changing the file should not be named lint:* IMO. As soon as it fixes things, it is not a linter anymore.

@javiereguiluz
Copy link
Member

javiereguiluz commented Jan 23, 2017

Even if this idea is changed to only provide a linter command and not a fixer, I'd love to see it happen.

(Context -> this morning, a minor error in a XLIFF translation file completely broke a bundle release: https://github.com/javiereguiluz/EasyAdminBundle/pull/1490)

@rvanlaak
Copy link
Contributor

@javiereguiluz we right now have the yml linter in our test suite, which saved us from releasing broken bundles several times already. So 👍 from me on that specific context too.

fabpot added a commit that referenced this issue Feb 18, 2017
…es (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
-------

7609e44 [Translation] Added a lint:xliff command for XLIFF files
@fabpot fabpot closed this as completed Feb 18, 2017
@fabpot fabpot reopened this Feb 18, 2017
@fabpot fabpot closed this as completed Feb 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants