Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanbekkum committed Sep 29, 2021
2 parents 0afb938 + 94795d4 commit 01758a5
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 70 deletions.
27 changes: 26 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
# Changelog

## [1.3.0] 29-09-2021

* Renamed functions to adhere to approved verbs and added aliases to still support the old function names (GitHub issue [#10](https://github.com/rvanbekkum/ps-xliff-sync/issues/10))
* New function `Test-BcAppXliffTranslations`, to be used for checking translations in a build pipeline for Microsoft Dynamics 365 Business Central apps. This function uses the `Sync-XliffTranslations` and `Test-XliffTranslations` functions to check for problems in all translation files of the BC app workspace folder.
* Add `Resolve-Path` for loading XLIFF files from or saving them to a filepath. (GitHub issue [#6](https://github.com/rvanbekkum/ps-xliff-sync/issues/6))
* Abort if file-load failed. (GitHub issue [#5](https://github.com/rvanbekkum/ps-xliff-sync/issues/5))
* Updated README with Installation instruction.

### Thank You (for 1.3.0)

* [Jan Hoek](https://github.com/jhoek) for filing [Issue #10 "Consider using standard verbs for your cmdlets"](https://github.com/rvanbekkum/ps-xliff-sync/issues/10)
* [Jan Hoek](https://github.com/jhoek) for filing [Issue #6 "Add support for relative paths"](https://github.com/rvanbekkum/ps-xliff-sync/issues/6)
* [Jan Hoek](https://github.com/jhoek) for filing [Issue #5 "In case of fatal exceptions, it might be better to stop the execution of the cmdlet"](https://github.com/rvanbekkum/ps-xliff-sync/issues/5)
* [Matthias König](https://github.com/aptMattKoe) for the suggestion of adding a small Installation section to the README.

## [1.2.0] 20-05-2021

* New function `Trans-XliffTranslations` by [Tomáš Žabčík](https://github.com/zabcik)
* Include units that already have needs-adaptation state in needs work count (GitHub issue [#8](https://github.com/rvanbekkum/ps-xliff-sync/issues/8))

### Thank You (for 1.2.0)

* [Tomáš Žabčík](https://github.com/zabcik) for your [Pull Request #9 "New Functions Trans-XliffTranslations"](https://github.com/rvanbekkum/ps-xliff-sync/pull/9)
* [Frédéric Vercaemst](https://github.com/fvet) for filing [Issue #8 "Translation(s) that need work - no output compared to Xliff-sync"](https://github.com/rvanbekkum/ps-xliff-sync/issues/8)

## [1.1.0] 06-03-2021

* Fix for `findByXliffGeneratorNoteAndSourceText` throwing error on variable not being found.
* Fix for incorrect assumption of `xml:space="preserve"` which would lead to errors in an attempt to insert whitespace/nodes.
* Fix/Improvement: Find by source (and developer note) would take the first unit with the same source text even if that unit did not have a translation, now it takes the first unit with the same source text with a translation to reuse translations.
* Command `Check-XliffTranslations` now returns the units that contain problems as an array. Useful if you want to do something with the outputs, e.g., extract/show more information or completely fail your build pipeline if any problems are found.

### Thank You
### Thank You (for 1.1.0)

* [Tomáš Žabčík](https://github.com/zabcik) for your [Pull Request #3 "fixing variable name"](https://github.com/rvanbekkum/ps-xliff-sync/pull/3)
* [Simone Colombo](https://github.com/simooo985) for filing [Issue #2 "Error syncing Angular translations"](https://github.com/rvanbekkum/ps-xliff-sync/issues/2)
Expand Down
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ Initial version with support for XLIFF 1.2 (support for XLIFF 2.0 follows later)

You need to have Powershell 5.0 or newer. This module uses classes.

## Installation

You can install the module from PowerShell Gallery by running:

```powershell
Install-Module -Name XliffSync
```

## Usage

### Synchronize XLIFF Translations
Expand Down Expand Up @@ -50,18 +58,19 @@ Please check the documentation of the function for more information and the avai

### Check XLIFF Translations

The `Check-XliffTranslations` function will check for missing translations and/or for problems in translations in a specified XLIFF file.
The `Test-XliffTranslations` function (alias: `Check-XliffTranslations`) will check for missing translations and/or for problems in translations in a specified XLIFF file.
To use the function you will need to specify the target file (`-targetPath`) and whether you want to check for missing translations (`-checkForMissing`) and/or problems in translations (`-checkForProblems`).
If you let the function check for problems, then you can use the `translationRules` parameter to specify which technical validation rules should be applied.

An example usage:

```powershell
Check-XliffTranslations -targetPath "C:\MyProject\My Project.nl-NL.xlf" -checkForMissing -reportProgress
$unitsWithProblems = Test-XliffTranslations -targetPath "C:\MyProject\My Project.nl-NL.xlf" -checkForMissing -reportProgress
```

When finished the function will report the number of missing translations and number of detected problems.
Translation units without translations will be marked with `state="needs-translation"` and translation units with a problem in the translation will be marked with a 'needs-work' state and an "XLIFF Sync"-note that explains the detected problem.
The function will return the translation units with problems, which you can assign to a variable (e.g., `$unitsWithProblems`) or omit, to have the output printed.

Please check the documentation of the function for more information and the available parameters.

Expand All @@ -76,3 +85,29 @@ Get-XliffTranslationsDiff -originalPath "C:\MyProject\OriginalVersion.xlf" -newP
```

Please check the documentation of the function for more information and the available parameters.

### Apply Translations to XLIFF Translation Files

The `Set-XliffTranslations` function (alias: `Trans-XliffTranslations`) will apply translations to the translation units in a target file with a translation base from a source file.

An example usage:

```powershell
Set-XliffTranslations -sourcePath "C:\MyProject\translationSource.xlf" -targetPath "C:\MyProject\translationTarget.xlf"
```

Please check the documentation of the function for more information and the available parameters.

### Check Translations of your Microsoft Dynamics 365 Business Central apps

The `Test-BcAppXliffTranslations` function (alias: `Check-BcAppXliffTranslations`) checks for problems in translations in the XLIFF translation files used for Microsoft Dynamics 365 Business Central apps.
It first synchronizes the translation files with the `.g.xlf` base file, and then checks for problems afterwards.
You can use this function in the build pipelines of your Business Central apps after the compile step, to detect problems in the translations of your Business Central apps.

An example usage:

```powershell
Test-BcAppXliffTranslations -translationRulesEnableAll -AzureDevOps 'error' -printProblems
```

Please check the documentation of the function for more information and the available parameters.
33 changes: 18 additions & 15 deletions XliffSync/Model/XlfDocument.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class XlfDocument {
hidden $xliffGeneratorNote;
hidden $sourceDeveloperNoteUnitMap;
hidden $sourceUnitMap;

[string] $developerNoteDesignation;
[string] $xliffGeneratorNoteDesignation;
[boolean] $preserveTargetAttributes;
Expand All @@ -32,7 +32,7 @@ class XlfDocument {

[string] GetSourceLanguage() {
switch ($this.Version()) {
"1.2" {
"1.2" {
[System.Xml.XmlNode] $fileNode = [XlfDocument]::GetNode('file', $this.root);
if ($fileNode) {
return $fileNode.'source-language';
Expand All @@ -48,7 +48,7 @@ class XlfDocument {
}

switch ($this.Version()) {
"1.2" {
"1.2" {
[System.Xml.XmlNode] $fileNode = [XlfDocument]::GetNode('file', $this.root);
if ($fileNode) {
$fileNode.'source-language' = $lng
Expand All @@ -60,7 +60,7 @@ class XlfDocument {

[string] GetTargetLanguage() {
switch ($this.Version()) {
"1.2" {
"1.2" {
[System.Xml.XmlNode] $fileNode = [XlfDocument]::GetNode('file', $this.root);
if ($fileNode) {
return $fileNode.'target-language';
Expand All @@ -76,7 +76,7 @@ class XlfDocument {
}

switch ($this.Version()) {
"1.2" {
"1.2" {
[System.Xml.XmlNode] $fileNode = [XlfDocument]::GetNode('file', $this.root);
if ($fileNode) {
$fileNode.'target-language' = $lng;
Expand All @@ -88,7 +88,7 @@ class XlfDocument {
[void] CreateUnitMaps([bool] $findByXliffGeneratorNoteAndSource, [bool] $findByXliffGeneratorAndDeveloperNote, [bool] $findByXliffGeneratorNote, [bool] $findBySourceAndDeveloperNote, [bool] $findBySource) {
[bool] $findByXliffGenNotesIsEnabled = $findByXliffGeneratorNoteAndSource -or $findByXliffGeneratorAndDeveloperNote -or $findByXliffGeneratorNote;
[bool] $findByIsEnabled = $findByXliffGenNotesIsEnabled -or $findBySourceAndDeveloperNote -or $findBySource;

$this.idUnitMap = @{}
$this.xliffGeneratorNoteSourceUnitMap = @{};
$this.xliffGeneratorNoteDeveloperNoteUnitMap = @{};
Expand Down Expand Up @@ -232,7 +232,7 @@ class XlfDocument {
[System.Xml.XmlNode] $parentNode = $this.cachedImportParentNode;
if (-not $this.cachedImportParentNode) {
switch ($this.Version()) {
"1.2" {
"1.2" {
# Parent will be the first 'group' or 'body' node.
$parentNode = [XlfDocument]::GetNode('group', $this.root);
if (-not $parentNode) {
Expand Down Expand Up @@ -435,7 +435,7 @@ class XlfDocument {
}
elseif ($targetChildNode -and ($this.Version() -eq "1.2")) {
$unit.InsertAfter($noteNode, $targetChildNode.NextSibling);

# Add the same whitespace after the note.
$newWhiteSpaceNode = $this.root.OwnerDocument.ImportNode($targetChildNode.PreviousSibling, $true);
$unit.InsertAfter($newWhiteSpaceNode, $noteNode);
Expand Down Expand Up @@ -501,10 +501,10 @@ class XlfDocument {
}

switch ($this.Version()) {
"1.2" {
"1.2" {
[System.Xml.XmlNode] $sourceChildNode = $unit.ChildNodes | Where-Object { $_.Name -eq "source" } | Select-Object -First 1;
[System.Xml.XmlNode] $targetChildNode = $unit.ChildNodes | Where-Object { $_.Name -eq "target" } | Select-Object -First 1;

if ($targetChildNode) {
$unit.ReplaceChild($targetNode, $targetChildNode);
}
Expand Down Expand Up @@ -646,6 +646,7 @@ class XlfDocument {
}

[void] SaveToFilePath([string] $filePath) {
$filePath = Resolve-Path $filePath
$this.root.OwnerDocument.Save($filePath);
}

Expand Down Expand Up @@ -766,7 +767,7 @@ class XlfDocument {
hidden static [XlfDocument] LoadFromRootNode([System.Xml.XmlNode] $rootNode) {
[XlfDocument] $doc = [XlfDocument]::new();
$doc.root = $rootNode;

if ($doc.Version() -ne "1.2") {
throw "Currently this module only supports XLIFF 1.2 Files. Support for XLIFF 2.0 will be added later.";
}
Expand All @@ -784,6 +785,8 @@ class XlfDocument {
}

static [XlfDocument] LoadFromPath([string] $filePath) {
$ErrorActionPreference = 'Stop'
$filePath = Resolve-Path $filePath
[xml] $fileContentXml = (New-Object System.Xml.XmlDocument);
$fileContentXml.Load($filePath);
return [XlfDocument]::LoadFromXmlDocument($fileContentXml);
Expand All @@ -792,17 +795,17 @@ class XlfDocument {
[void] AddFromPath([string] $filePath) {
[xml] $fileContentXml = (New-Object System.Xml.XmlDocument);
$fileContentXml.Load($filePath);
$xlfDoc = [XlfDocument]::LoadFromXmlDocument($fileContentXml);
$xlfDoc = [XlfDocument]::LoadFromXmlDocument($fileContentXml);

if ($null -ne $this.root) {
[xml] $xmlDoc = $this.root.OwnerDocument;
$group = [XlfDocument]::GetNode('group', $xlfDoc.root);
$group = [XlfDocument]::GetNode('group', $xlfDoc.root);
$imported = $xmlDoc.ImportNode($group, $true);
$groupImported = [XlfDocument]::GetNode('group', $this.root);
$groupImported.AppendChild($imported);
} else {
$this.root = $xlfDoc.root;
}
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions XliffSync/Public/Get-XliffTranslationsDiff.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#
<#
.Synopsis
Compares XLIFF translation files and creates a new XLIFF translation files with the differences.
.Description
Expand Down Expand Up @@ -77,4 +77,5 @@ function Get-XliffTranslationsDiff {

Write-Host "Saving document to $diffPath"
$diffDocument.SaveToFilePath($diffPath);
}
}
Export-ModuleMember -Function Get-XliffTranslationsDiff
Loading

0 comments on commit 01758a5

Please sign in to comment.