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

Add support for relative paths #6

Closed
jhoek opened this issue Mar 30, 2021 · 5 comments
Closed

Add support for relative paths #6

jhoek opened this issue Mar 30, 2021 · 5 comments
Labels
enhancement New feature or request shipped Issue is available in the public release.

Comments

@jhoek
Copy link
Contributor

jhoek commented Mar 30, 2021

When I ran

Sync-XliffTranslations -sourcePath '.\Translations\MyCompanyName Extension.g.xlf' -targetPath .\Translations\translation.nl-NL.xlf -targetLanguage nl-NL -findBySourceAndDeveloperNote

from the folder of my AL-project, the cmdlet claims that the source path could not be found, but it appears to be looking for it in my home folder (c:\Users\MyUserName). Please consider adding support for relative paths, such as ".\Translations\MyFile.txt" and "..\Translations\MyFile.txt".

P.S.: I haven't tested this, but the cmdlets may also lack support for special paths such as PowerShell drives (MyDrive:\MyFile.txt) and ~ (which represents the user's home folder).

@rvanbekkum
Copy link
Owner

Hi @jhoek,

Thank you for filing the issue!

I am not able to reproduce it yet though. 😕 Not saying that the issue is not there, but I can't get it to throw an error yet when using relative paths.
Could you give me some more information on when you are running into this? Could it be that the file really was not there during your test (you never know, I've had that before 😅)?

@rvanbekkum rvanbekkum added the input-needed Extra attention is needed label Apr 7, 2021
@jhoek
Copy link
Contributor Author

jhoek commented Apr 9, 2021

No problem, @rvanbekkum. You are passing PowerShell-style paths directly to XmlDocument.Load, which is unaware of the path syntax and the PowerShell current directory.

Sync-XliffTranslations -sourcePath ~/Desktop/xlifftest/Translations/xlifftest.g.xlf -targetPath ~/Desktop/xlifftest/Translations/xlifftest.nl-NL.xlf -targetLanguage nl-NL -parseFromDeveloperNote

results in

Loading source document ~/Desktop/xlifftest/translations/xlifftest.g.xlf 
MethodInvocationException: /Users/jhoek/.local/share/powershell/Modules/XliffSync/1.1.0.0/Model/XlfDocument.ps1:788
Line |
 788 |          $fileContentXml.Load($filePath);
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Load" with "1" argument(s): "Could not find a part of the path
     | '/Users/jhoek/~/Desktop/xlifftest/translations/xlifftest.g.xlf'."

As you can see, what XmlDocument tries to load is my home folder combined with the path from the parameter value (/Users/jhoek/~/Desktop/xlifftest/translations/xlifftest.g.xlf).

B.t.w. - Test-path ~/Desktop/xlifftest/translations/xlifftest.g.xlf returns true, meaning Powershell can understand and find the path in question.

@jhoek
Copy link
Contributor Author

jhoek commented Apr 9, 2021

I just realised that you may have tested with a relative path that XmlDocument.Load could understand, e.g. one that starts with a single or double "." (for either the current or parent directory). Also, at the time of your test, your current folder according to .NET (initially your home folder, judging from the above) may coincidentally have matched your current folder in PowerShell (which also uses your home folder as a default). Under those two conditions, your test may have succeeded where mine failed.

@rvanbekkum rvanbekkum added enhancement New feature or request and removed input-needed Extra attention is needed labels Apr 18, 2021
@warlof
Copy link

warlof commented Aug 25, 2021

Hey,

I'm encountering the same issue when using relative path.
Here is a sample :

Import-Module ~\sources\repos\ps-xliff-sync\XliffSync\XliffSync.psm1
Sync-XliffTranslations -sourcePath '.\4PS_Construct_W1_French_language_(France)\Translations\4PS Construct W1.g.xlf' -targetPath '.\4PS_Construct_W1_French_language_(France)\Translations\4PS Construct W1.fr-FR.xlf' -reportProgress -findBySource -findByXliffGeneratorNoteAndSource -findByXliffGeneratorAndDeveloperNote -findByXliffGeneratorNote

The upper command is resulting in a batch of exceptions

Loading source document .\4PS_Construct_W1_French_language_(France)\Translations\4PS Construct W1.g.xlf
Exception lors de l'appel de « Load » avec « 1 » argument(s) : « Impossible de trouver une partie du chemin d'accès 'C:\WINDOWS\system32\4PS_Construct_W1_French_language_(France)\Translations\4PS Construct W1.g.xlf'. »
Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Model\XlfDocument.ps1:788 : 9
+         $fileContentXml.Load($filePath);
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

La propriété « developerNoteDesignation » est introuvable dans cet objet. Vérifiez qu’elle existe et qu’elle peut être définie.
Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Public\Sync-XliffTranslations.ps1:99 : 5
+     $mergedDocument.developerNoteDesignation = $developerNoteDesignat ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                La propriété « xliffGeneratorNoteDesignation » est introuvable dans cet objet. Vérifiez qu’elle existe et qu’elle peut être définie.                                                                                                                                           Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Public\Sync-XliffTranslations.ps1:100 : 5                                                                                                                                                         +     $mergedDocument.xliffGeneratorNoteDesignation = $xliffGeneratorNo ...                                                                                                                                                                                                    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                                                                            + CategoryInfo          : InvalidOperation : (:) [], RuntimeException                                                                                                                                                                                                          + FullyQualifiedErrorId : PropertyNotFound                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                La propriété « missingTranslation » est introuvable dans cet objet. Vérifiez qu’elle existe et qu’elle peut être définie.                                                                                                                                                      Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Public\Sync-XliffTranslations.ps1:101 : 5                                                                                                                                                         +     $mergedDocument.missingTranslation = $missingTranslation;                                                                                                                                                                                                                +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                                                                                     + CategoryInfo          : InvalidOperation : (:) [], RuntimeException                                                                                                                                                                                                          + FullyQualifiedErrorId : PropertyNotFound                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                La propriété « parseFromDeveloperNoteSeparator » est introuvable dans cet objet. Vérifiez qu’elle existe et qu’elle peut être définie.                                                                                                                                         Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Public\Sync-XliffTranslations.ps1:102 : 5                                                                                                                                                         +     $mergedDocument.parseFromDeveloperNoteSeparator = $parseFromDevel ...                                                                                                                                                                                                    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                                                                            + CategoryInfo          : InvalidOperation : (:) [], RuntimeException                                                                                                                                                                                                          + FullyQualifiedErrorId : PropertyNotFound

La propriété « preserveTargetAttributes » est introuvable dans cet objet. Vérifiez qu’elle existe et qu’elle peut être définie.
Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Public\Sync-XliffTranslations.ps1:103 : 5
+     $mergedDocument.preserveTargetAttributes = $preserveTargetAttribu ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

La propriété « preserveTargetAttributesOrder » est introuvable dans cet objet. Vérifiez qu’elle existe et qu’elle peut être définie.
Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Public\Sync-XliffTranslations.ps1:104 : 5
+     $mergedDocument.preserveTargetAttributesOrder = $preserveTargetAt ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Loading target document .\4PS_Construct_W1_French_language_(France)\Translations\4PS Construct W1.fr-FR.xlf
Exception lors de l'appel de « Load » avec « 1 » argument(s) : « Impossible de trouver une partie du chemin d'accès 'C:\WINDOWS\system32\4PS_Construct_W1_French_language_(France)\Translations\4PS Construct W1.fr-FR.xlf'. »
Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Model\XlfDocument.ps1:788 : 9
+         $fileContentXml.Load($filePath);
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Impossible d’appeler une méthode dans une expression Null.
Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Public\Sync-XliffTranslations.ps1:120 : 5
+     [string] $language = $targetDocument.GetTargetLanguage();
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Creating Maps in memory for target document's units.
Impossible d’appeler une méthode dans une expression Null.
Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Public\Sync-XliffTranslations.ps1:135 : 13
+             $targetDocument.CreateUnitMaps($findByXliffGeneratorNoteA ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Retrieving translation units from source document
Impossible d’appeler une méthode dans une expression Null.
Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Public\Sync-XliffTranslations.ps1:140 : 5
+     [int] $unitCount = $mergedDocument.TranslationUnitNodes().Count;
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Processing unit nodes... (Please be patient)
Impossible d’appeler une méthode dans une expression Null.
Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Public\Sync-XliffTranslations.ps1:159 : 5
+     $mergedDocument.TranslationUnitNodes() | ForEach-Object {
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Detected 0 source text change(s).
Saving document to .\4PS_Construct_W1_French_language_(France)\Translations\4PS Construct W1.fr-FR.xlf
Impossible d’appeler une méthode dans une expression Null.
Au caractère C:\Users\Me\source\repos\4PS\ps-xliff-sync\XliffSync\Public\Sync-XliffTranslations.ps1:284 : 5
+     $mergedDocument.SaveToFilePath($targetPath);
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

However, give that one is working :

Import-Module ~\sources\repos\ps-xliff-sync\XliffSync\XliffSync.psm1
$srcXlf = "C:\Users\Me\source\repos\4PS\4PS_Construct_W1_French_language_(France)\Translations\4PS Construct W1.g.xlf"
$dstXlf = "C:\Users\Me\source\repos\4PS\4PS_Construct_W1_French_language_(France)\Translations\4PS Construct W1.fr-FR.xlf"
Sync-XliffTranslations -sourcePath $srcXlf -targetPath $dstXlf -reportProgress -findBySource -findByXliffGeneratorNoteAndSource -findByXliffGeneratorAndDeveloperNote -findByXliffGeneratorNote

It seems it's using System32 as root directory rather than current path.

@rvanbekkum rvanbekkum added the in-progress One of the contributors is working on this. label Sep 21, 2021
@rvanbekkum rvanbekkum added ships-in-future-update Resolution will be available in the next release. shipped Issue is available in the public release. and removed in-progress One of the contributors is working on this. ships-in-future-update Resolution will be available in the next release. labels Sep 29, 2021
@rvanbekkum
Copy link
Owner

rvanbekkum commented Sep 29, 2021

Changes for this have been shipped in the new release, version 1.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request shipped Issue is available in the public release.
Projects
None yet
Development

No branches or pull requests

3 participants