Modules/businessdev.ALbuild.Apps/Private/Test-BcXliffNeedsWork.ps1

function Test-BcXliffNeedsWork {
    <#
    .SYNOPSIS
        Runs technical "needs-work" validation rules on a source/target translation pair.
    .DESCRIPTION
        Internal, pure helper. Returns an array of rule violation messages (empty when the
        translation passes). Rules:
          - Placeholders: the set of %1/{0}/#1 placeholders must match between source and target.
          - OptionMemberCount: comma-separated option member counts must match.
          - ConsecutiveSpaces: presence of consecutive spaces must be consistent.
          - SourceEqualsTarget: when the languages are the same, target must equal source.
    #>

    [CmdletBinding()]
    [OutputType([string[]])]
    param(
        [AllowNull()] [AllowEmptyString()] [string] $Source,
        [AllowNull()] [AllowEmptyString()] [string] $Target,
        [switch] $SameLanguage
    )

    $issues = [System.Collections.Generic.List[string]]::new()
    if ([string]::IsNullOrEmpty($Target)) { return @() }  # missing translations are handled separately

    $placeholdersOf = {
        param($text)
        $found = [regex]::Matches($text, '%\d+|\{\d+\}|#\d+')
        return @($found | ForEach-Object { $_.Value } | Sort-Object)
    }
    $sourcePlaceholders = & $placeholdersOf $Source
    $targetPlaceholders = & $placeholdersOf $Target
    if (($sourcePlaceholders -join '|') -ne ($targetPlaceholders -join '|')) {
        $issues.Add("Placeholders differ (source: '$($sourcePlaceholders -join ',')', target: '$($targetPlaceholders -join ',')').")
    }

    $sourceCommas = ([regex]::Matches($Source, ',')).Count
    $targetCommas = ([regex]::Matches($Target, ',')).Count
    if ($sourceCommas -ne $targetCommas) {
        $issues.Add("Option member count differs (source has $sourceCommas comma(s), target has $targetCommas).")
    }

    $sourceHasDouble = $Source -match ' '
    $targetHasDouble = $Target -match ' '
    if ($sourceHasDouble -ne $targetHasDouble) {
        $issues.Add('Consecutive spaces are inconsistent between source and target.')
    }

    if ($SameLanguage -and ($Source -ne $Target)) {
        $issues.Add('Source and target languages are the same but the texts differ.')
    }

    return @($issues)
}