Skip to content
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

Full paths in xliff jms:reference-file tag at Windows environments #447

Open
jleehr opened this issue May 30, 2017 · 1 comment
Open

Full paths in xliff jms:reference-file tag at Windows environments #447

jleehr opened this issue May 30, 2017 · 1 comment

Comments

@jleehr
Copy link

jleehr commented May 30, 2017

Q A
Bundle version dev-master (524a327)
Symfony version 2.8.21
PHP version 7.0.9

Expected behavior

Relative paths in jms:reference-file tag in xliff files.
<jms:reference-file line="131">/../src/AppBundle/yourFile.php</jms:reference-file>

Actual behavior

Mixedup paths on Windows
<jms:reference-file line="131">\..\..\..\..\..\..\..\C:/Users/yourPath/app/../src\AppBundle\yourFile.php\</jms:reference-file>

Steps to reproduce

Extract translations at a Windows environment.

config.yml:

jms_translation:
    configs:
        app:
            dirs: ["%kernel.root_dir%/../src/AppBundle/"]

This is a related issue to #366 and was noticed by jeanlamy on 4 Nov 2016.

@bulhi
Copy link

bulhi commented Jan 2, 2018

Hello everyone. This is pretty annoying issue, not only because the path is not valid, but more importantly because the absolute path which is kept in the string causes massive merge conflicts when two people update translations simultaneously. That basically forces you to always throw away all changes in one of the branches. So I finally found some time to investigate it, and located the problem, but I'm not sure what would be the best solution.

Actual code generating the path is in FileSourceFactory in method getRelativePath($path), where on Windows kernel root path looks like
D:\www\symfonyTst\app
but file path like
D:/www/symfonyTst/app\Resources\views\default\index.html.twig
thus the logic comparing these two doesn't work and also exploding the string based on platform directory separator below produces unexpected results. So the easy solution is to fix it here, but I was curious why the file path arrives broken like this and the reason is that in JMS\TranslationBundle\DependencyInjection\Configuration the config "dirs" path is always normalized to use forward slashes. So another solution, and in my opinion the more "correct" one, is to remove this logic from there. Extraction then works correctly, but I'm not sure, if this is important for some other reason.

Another problem with this solution is that if you had a team with people working on mixed platforms (Linux/Windows), you would have the same merge problem again, only this time caused by different directory separators in all paths. Also considering the fact that on Windows you can actually use both forward and backslash (i.e. pasting the path into Windows explorer etc.), the more practical solution would probably be to just always use forward slashes in the dumped xliff regardless of the platform.

So the fix is in both cases very simple, and I can make a PR, if desired, but I would rather first hear someone else's opinion on this.

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

No branches or pull requests

2 participants