Skip to content

[Translation] XliffLintCommand: allow .xliff file extension #32548

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

Merged
merged 1 commit into from
Aug 13, 2019
Merged

[Translation] XliffLintCommand: allow .xliff file extension #32548

merged 1 commit into from
Aug 13, 2019

Conversation

codegain
Copy link
Contributor

@codegain codegain commented Jul 15, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
License MIT

I ran into a problem with XLIFF files having an *.xliff extension and a "target-language" attribute.
The command always outputted: There is a mismatch between the language included in the file name and the value used used in the "target-language" attribute of the file.

The "target-language" attribute was set to "en" and the filename was also "menu.en.xliff".
After reading the source code, I realized that this regex does not respect other valied file extensions such as "xliff" for these files and therefore throws this (rather confusing) error.

@javiereguiluz
Copy link
Member

In other parts of the application I think we said: xlf is the only valid extension for XLIFF files, so we won't add support for xliff extension. See for example #22440.

So, in theory, we shouldn't merge this for consistency ... or we should add support for xliff everywhere we support xlf. I don't have a strong opinion about this.

@codegain
Copy link
Contributor Author

My opinion is that if symfony is able to load .xliff files (which it is without any problems), it should be able to lint these .xliff files.

On this line (218 on master):

if (!\in_array($file->getExtension(), ['xlf', 'xliff'])) {

The linter explicitly loads .xlf and .xliff files.

So this pull-request fixes a bug where xliff files are being loaded by the linter (removing that would be a BC break in my opinion), but can't be properly linted because of the wrong regex.

@nicolas-grekas nicolas-grekas added this to the next milestone Jul 17, 2019
@nicolas-grekas
Copy link
Member

(should target 4.4 btw)

@nicolas-grekas nicolas-grekas changed the title XliffLintCommand: Respect other supported file extensions [Translation] XliffLintCommand: Respect other supported file extensions Jul 17, 2019
@codegain codegain changed the base branch from master to 4.4 July 18, 2019 15:28
@codegain
Copy link
Contributor Author

codegain commented Jul 18, 2019

(should target 4.4 btw)

@nicolas-grekas Sorry, I'm unfamiliar with the GitHub branch targeting. I think I screwed this up >.<
I think I will open a new pull-request with your requested changes.

EDIT: Ok, I think I got it reversed, will check how to target 4.4

@codegain codegain changed the base branch from 4.4 to master July 18, 2019 15:31
@codegain
Copy link
Contributor Author

in strict mode, I'd suggest raising an error when xliff is used

@nicolas-grekas I added another error message if "xliff" is used with strict mode enabled. Could you have a look at it again?

Altough that change does not resolve my issue, because I am using strict mode unintentionally and I found no "easy" way to disable it. The flag to enable strict mode is set to "true" by default in the constructor. I think there should be an option like "--no-strict-mode" to disable it via the command line.

@nicolas-grekas
Copy link
Member

@codegain but why don't you use the xlf extension? That's the only standard one AFAIK?

@codegain
Copy link
Contributor Author

codegain commented Jul 23, 2019

@codegain but why don't you use the xlf extension? That's the only standard one AFAIK?

@nicolas-grekas I am using poeditor.com for translations which only works with .xliff files and shows the error "File format unsupported" if an .xlf file is uploaded.

According to a section in the specs for XLIFF 1.2 (http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html):

D.4. XLIFF File Extension
XLIFF documents use the .xlf extension. No other extension is recommended by the specification.

the .xlf extension is recommeded, but not strictly required.

The XLIFF 2.0 specs (http://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html) make no preference towards any file extension.

@nicolas-grekas
Copy link
Member

Did you report the issue to poeditor? That's where the real issue is to me.

@codegain
Copy link
Contributor Author

@nicolas-grekas Their response:

Since we support only iOS xliff files, we allow imports only with the .xliff extension, because that's the one specific to iOS.
Uploading .xlf files may work after changing the extenstion to .xliff, but if your files are not in the same format as the iOS xliff format, data can get lost during this process.
We have a sample of the iOS xliff format here:
https://poeditor.com/localization/files/xliff

I had no idea that any sort of "iOS xliff" exists, because it works perfectly fine with symfony xlf files (if I change the extension to ".xliff").
I would like that this change makes into the XliffLintCommand, because my current workaround is to

  1. rename all files to ".xlf"
  2. run the lint:xliff command
  3. rename all files back to ".xliff"

@nicolas-grekas
Copy link
Member

Thanks for the details. If everybody else is OK to seamlessly accept .xliff files, let's do it
/cc @symfony/deciders

@codegain
Copy link
Contributor Author

codegain commented Aug 1, 2019

Thanks for the details. If everybody else is OK to seamlessly accept .xliff files, let's do it

@nicolas-grekas @Tobion Just to clarify: Should the command now seamlessly accept .xliff files (without an additional error message) or raise an error if .xliff is used in strict mode?

@fabpot
Copy link
Member

fabpot commented Aug 9, 2019

I would accept loading both without any messages.

@nicolas-grekas nicolas-grekas changed the title [Translation] XliffLintCommand: Respect other supported file extensions [Translation] XliffLintCommand: allow .xliff file extension Aug 13, 2019
@nicolas-grekas nicolas-grekas changed the base branch from master to 4.4 August 13, 2019 07:15
@nicolas-grekas
Copy link
Member

Thank you @codegain.

@nicolas-grekas nicolas-grekas merged commit dba6a21 into symfony:4.4 Aug 13, 2019
nicolas-grekas added a commit that referenced this pull request Aug 13, 2019
…nsion (codegain)

This PR was merged into the 4.4 branch.

Discussion
----------

[Translation] XliffLintCommand: allow .xliff file extension

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| License       | MIT

I ran into a problem with XLIFF files having an *.xliff extension and a "target-language" attribute.
The command always outputted: There is a mismatch between the language included in the file name and the value used used in the "target-language" attribute of the file.

The "target-language" attribute was set to "en" and the filename was also "menu.en.xliff".
After reading the source code, I realized that this regex does not respect other valied file extensions such as "xliff" for these files and therefore throws this (rather confusing) error.

Commits
-------

dba6a21 [Translation] XliffLintCommand: allow .xliff file extension
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
This was referenced Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants