HodorNV / ALOps

ALOps
59 stars 24 forks source link

[FEATURE REQUEST] Check for missing translations #674

Open Arthurvdv opened 1 year ago

Arthurvdv commented 1 year ago

Is your feature request related to a problem? Please describe. It would be great to have a validation in our pipelines to be sure not a single translation is missing.

Caption = 'Start Date', comment = 'NLB="Begindatum"';

Some projects are using the comments functionality and use in our pipelines the Invoke-EVGenerateXliffFiles.ps1 script (with some small modifications) to generate to translations files. We could argue on the best pratice on this (I know our opinion on this ;-)), but the feature request is not about this.

Due to the error prone way of working with the comments, a translation is easily missed and quite often discovered by the consultant of customer after deployment. So it would be great to have a automated way to verify if there are missing translations. Also when you're working with an external application for translations it would be good to know if there are somehow missing translations.

Describe the solution you'd like Verify if there are missing translations compared with the base .g.xlf file generated after compiling the app. If possible a parameter to specify the expected languages like; "nl-BE,fr-BE" to specify with translations to check.

Could be included in the Compile step, but to prevent clutter this could also be it's own separate action. This separate action then should be set after the compile step in the pipeline.

Describe alternatives you've considered There's an example out there: XliffCheck, but comes with it limitations. A fatal error occurred. The required library hostfxr.dll could not be found. Need to install the .net core run time on the agent or re-publish with Deployment Mode: Self Contained which grows the solution to a whopping ±30MB and then I need to write (and maintain) some PowerShell to get everything going.

waldo1001 commented 1 year ago

I understand.

While it's not up to me to follow up whether this is good practice or not (I don't think "translations" should be part of development), I do think there might be a place in "some stage" of a (cd?) pipeline... .

I'll talk with the devteam!

waldo1001 commented 1 year ago

Talked to the devteam, not a bad idea, but it'll take time to implement.

Arthurvdv commented 1 year ago

Thank you for considering this and providing feedback. We'll wait (im)patiently 😜 on this coming available in a future release of ALOps.

fvet commented 1 year ago

Just sharing, as we have this already as a custom step in our pipelines, using XliffSync (which is also used in VS Code) ;)

Our method does not checks on the (lack of) presence of the 'comment' tags, but on the lack of translations in the xliff file. The build pipeline runs following steps:

Script used to check for missing translations

[CmdletBinding()]
param (       
    [Parameter(Mandatory = $true)]
    [string]$BuildProjectFolder,
    [string]$SourceBranch,
    [string]$TargetBranch,
    [boolean]$Enable = $true
)

# $buildProjectFolder = "C:\Projects\Dynavision\Dynavision Core\"
# $SourceBranch = 'merge'
# $TargetBranch = 'development'
# $enable = $true

if (!$Enable) { 
    Write-Host "Check & Sync translations is disabled. To enable, update the variable 'enable_xliffcheck' in the PipelineVariables group."
    exit
}

if (-not (Get-Module -ListAvailable -Name 'XliffSync')) {
    Write-Host ""
    Install-Module -Name 'XliffSync' -Force
}

function GetXliffFileHash {  
    Write-Host "Get xlf files from $buildProjectFolder"
    return Get-ChildItem -Path $buildProjectFolder -Recurse -Filter '*.xlf' | Where-Object { -not $_.FullName.EndsWith('.g.xlf') } | Select-Object -Property Name,Length, @{name = "Hash"; expression = { (Get-FileHash $_.FullName).hash } }                               
}

$XliffFileHashBeforeSync = GetXliffFileHash

# References
# https://robvanbekkum.nl/additional-build-steps/#checking-xliff-translation-files-for-errors-in-build-pipelines
# https://github.com/rvanbekkum/ps-xliff-sync/blob/c29cea5bac623c78b3d4674b97c3c66654607bfa/README.md

$AppFolders = @("App")
$SyncAdditionalParameters = @{
    "preserveTargetAttributesOrder"   = $true
    "findBySource"                    = $true 
    "findBySourceAndDeveloperNote"    = $true
    "parseFromDeveloperNote"          = $true
    "parseFromDeveloperNoteOverwrite" = $true
    "parseFromDeveloperNoteSeparator" = "||"
    "parseFromDeveloperNoteTrimCharacters" = """"
}

if($SourceBranch.ToLower() -match "master"){ 
    $AzureDevOps = 'error'
} elseif($TargetBranch.ToLower() -match "development" -or $TargetBranch.ToLower() -match "targetbranch"){ 
    $AzureDevOps = 'warning'
} else {
    $AzureDevOps = 'error'    
}

Write-Host "##[group]Variables"
Write-Host "Source Branch: $SourceBranch"
Write-Host "Target Branch: $TargetBranch"
Write-Host "AzureDevOps: $AzureDevOps"
Write-Host "##[endgroup]"

Test-BcAppXliffTranslations -printProblems -appFolders $AppFolders -translationRules @("OptionMemberCount", "OptionLeadingSpaces", "Placeholders", "ConsecutiveSpacesConsistent", "ConsecutiveSpacesExist") -restrictErrorsToLanguages @("nl-BE", "nl-NL") -buildProjectFolder $BuildProjectFolder -syncAdditionalParameters $SyncAdditionalParameters -AzureDevOps $AzureDevOps # -reportProgress -FormatTranslationUnit 

$XliffFileHashAfterSync = GetXliffFileHash

Write-Host "##[group]File Hashes"
$XliffFileHashBeforeSync | Out-String | Write-Host
$XliffFileHashAfterSync | Out-String | Write-Host
Write-Host "##[endgroup]"

if ($XliffFileHashBeforeSync -and $XliffFileHashAfterSync) {
    $CompareObjects = Compare-Object -Ref $XliffFileHashBeforeSync -Dif $XliffFileHashAfterSync -Property Name, Hash 
    $NoOfChangedXliffs = $CompareObjects.Count
}

# Awaiting resolution of https://github.com/rvanbekkum/ps-xliff-sync/issues/38

if ($NoOfChangedXliffs -eq 0) {
    Write-Host "##vso[task.setvariable variable=xliff_changed;]false"
}
else {
    Write-Host "##vso[task.setvariable variable=xliff_changed;]true"
}