Save/Save-TranslationFilesToStorage.ps1

function Extract-And-Save-AllTranslations {
    param (
        [string]$appFolderPath = "$ENV:appFolderPath",
        [string]$translationsGlobalFolder = "$ENV:translationsGlobalFolder"
    )

    if (-Not (Test-Path -Path $translationsGlobalFolder)) {
        New-Item -ItemType Directory -Path $translationsGlobalFolder | Out-Null
    } else {
        Remove-Item -Path "$translationsGlobalFolder\*" -Recurse -Force
    }

    $tempExtractFolder = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.Guid]::NewGuid().ToString())
    New-Item -ItemType Directory -Path $tempExtractFolder | Out-Null

    foreach ($appFile in Get-ChildItem -Path $appFolderPath -Filter "*.app") {
        try {
            Extract-AppFileToFolder -appFilename $appFile.FullName -AppFolder $tempExtractFolder

            $appJson = Get-AppJsonFromAppFile -appFile $appFile.FullName
            $appName = $appJson.name

            $translationsPath = Join-Path -Path $tempExtractFolder -ChildPath "Translations"
            $xlfFile = Get-ChildItem -Path $translationsPath -Filter "*g.xlf" | Select-Object -First 1

            if ($xlfFile) {
                $appTranslationsFolder = Join-Path -Path $translationsGlobalFolder -ChildPath $appName
                New-Item -ItemType Directory -Path $appTranslationsFolder -Force | Out-Null

                Copy-Item -Path $xlfFile.FullName -Destination $appTranslationsFolder -Force
                Write-Output "File '$($xlfFile.Name)' saved in '$appTranslationsFolder'."
            } else {
                Write-Output "Translation file ending in 'g.xlf' not found for $appName in $translationsPath."
            }

            Remove-Item -Path "$tempExtractFolder\*" -Recurse -Force
        } catch {
            Write-Output "Error processing file '$($appFile.Name)': $_"
        }
    }

    Remove-Item -Path $tempExtractFolder -Recurse -Force
}


function Upload-TranslationsToAzureBlob {
    param (
        [string]$localTranslationsFolder = "$ENV:translationsGlobalFolder",
        [string]$azureContainerName = "$ENV:azureContainerName",
        [string]$connectionString = "$ENV:storageConnectionString",
        [string]$translationFolderBlobPath = "$ENV:translationFolderBlobPath"
    )

    if ($translationFolderBlobPath -eq $null -or $translationFolderBlobPath -eq "") {
        Write-Error "Parameter 'translationFolderBlobPath' not found"
    }
    if (-not (Get-Module -ListAvailable -Name "Az.Storage")) {
        Write-Output "Module 'Az.Storage' not found. Installing..."
        Install-Module -Name Az.Storage -Force -Scope CurrentUser -AllowClobber
    }
    Import-Module Az.Storage

    $storageContext = New-AzStorageContext -ConnectionString $connectionString

    $container = Get-AzStorageContainer -Name $azureContainerName -Context $storageContext -ErrorAction SilentlyContinue
    if (-not $container) {
        Write-Output "Container '$azureContainerName' not found in Azure Storage. Please verify the container name."
        return
    }

    foreach ($appFolder in Get-ChildItem -Path $localTranslationsFolder -Directory) {
        $appName = $appFolder.Name

        $xlfFile = Get-ChildItem -Path $appFolder.FullName -Filter "*g.xlf" | Select-Object -First 1
        if ($xlfFile) {
            $blobReference = "$translationFolderBlobPath/$($xlfFile.Name)"

            $blob = Set-AzStorageBlobContent -File $xlfFile.FullName -Container $azureContainerName -Blob $blobReference -Context $storageContext -Force
            Write-Output "Uploaded '$($xlfFile.Name)' to container '$azureContainerName' under folder '$translationFolderBlobPath'."
        } else {
            Write-Output "No 'g.xlf' file found in folder for application '$appName'."
        }
    }
}

Write-Host "##[group]Extract and save translations"
Extract-And-Save-AllTranslations
Write-Host "##[endgroup]"

Write-Host "##[group]Upload translations to Azure Blob"
Upload-TranslationsToAzureBlob
Write-Host "##[endgroup]"