Translation/Test-TranslationIsComplete.ps1

function Test-TranslationIsComplete {
    param (
        # the directory with the source code of the app to be translated
        [Parameter(Mandatory=$false)]
        [string]
        $SourceDir = (Get-Location),
        # whether to surpress the error
        [Parameter(Mandatory=$false)]
        [switch]
        $SurpressError
    )
    
    $EnvJson = ConvertFrom-Json (Get-Content (Join-Path $SourceDir 'environment.json') -Raw)
    if ($TranslationSource -eq '' -or $null -eq $TranslationSource) {
        $TranslationSource = Join-Path $SourceDir $EnvJson.translationSource
    }

    if (!(Test-Path $TranslationSource)) {
        if ($SurpressError.IsPresent) {
            return $false
        }
        else {
            throw 'Could not find translation source file.'
        }
    }

    foreach ($Translation in $EnvJson.translations) {
        $TranslationPath = Join-Path $SourceDir (Join-Path 'Translations' ('{0}-{1}.xlf' -f $Translation.language, $Translation.country))
        if (!(Test-Path $TranslationPath)) {
            if ($SurpressError.IsPresent) {
                return $false
            }
            else {
                throw ('Translation file {0}-{1} is missing' -f $Translation.language, $Translation.country)
            }
        }
        else {
            Sync-TranslationUnits -SourcePath $TranslationSource -OutputPath $TranslationPath | Out-Null
            if ($null -ne (Get-StringsToTranslate -SourcePath $TranslationPath)) {
                if ($SurpressError.IsPresent) {
                    return $false
                }
                else {
                    throw ('Translation file {0}-{1} has missing translations' -f $Translation.language, $Translation.country)
                }
            }
        }
    }

    return $true
}

Export-ModuleMember -Function Test-TranslationIsComplete