public/Build-SfGlobalValueSetTranslationMetadata.ps1

function Build-SfGlobalValueSetTranslationMetadata {

    <#
        .SYNOPSIS
        Builds the *.globalValueSetTranslation-meta.xml files from the metadata model.

        .DESCRIPTION
        Processes the global value set translations as given in table [_GlobalValueSetTranslationss] in the metadata model.
        The picklist label translations will be collected from table [_PicklistValues] in the metadata model.

        .LINK
        Build-SfGlobalValueSetMetadata

        .LINK
        Import-SfMetadataModel

        .LINK
        https://codeberg.org/uwe-braig/sf-metadata-toolkit
    #>


    [CmdletBinding()]
    param (
        # The metadata model as imported from *.csv and/or *.xlsx with Import-SfMetadataModel
        [Parameter(Mandatory, Position = 0)]
        [PSCustomObject] $MetadataModel,

        # List of names of the GlobalValueSet to be built. If left empty, all will be built.
        [Parameter()]
        [string[]] $ValueSetNames,

        # List of language codes, e.g. ('en_US', 'de')
        [Parameter(Mandatory)]
        [string[]] $LanguageCodes,

        # Target path for the resulting *.xml files. Default is [./force-app/main/default].
        [Parameter()]
        [string] $TargetPath = './force-app/main/default'
    )

    $ErrorActionPreference = 'Stop'
    [bool] $IsDebug   = $DebugPreference   -ne 'SilentlyContinue'
    [bool] $IsVerbose = $VerbosePreference -ne 'SilentlyContinue'

    # --- prepare target directories
    $GlobalValueSetTranslationPath = Join-Path $TargetPath 'globalValueSetTranslations'
    $GlobalValueSetTranslationDirectory = New-Item -ItemType Directory -Path $GlobalValueSetTranslationPath -Force
    Write-Debug "Writing to: $($GlobalValueSetTranslationDirectory.FullName)"

    # --- build the global value set translations, but only those that match the filter
    foreach ($ValueSet in $MetadataModel.Tables._GlobalValueSets) {
        if (
            (!$ValueSetNames) -or
            ($ValueSetNames -contains $ValueSet._Name) -or
            ($ValueSetNames -contains "GlobalValueSet:$($ValueSet._Name)")
            ) {

            foreach ($LanguageCode in $LanguageCodes) {
                $xmlString = ConvertTo-SfGlobalValueSetTranslationXml -ValueSet $ValueSet -LanguageCode $LanguageCode -PicklistValues $MetadataModel.Tables._PicklistValues
                Set-MetadataXmlFile 'GlobalValueSetTranslation' "$($ValueSet._Name)-$LanguageCode" '.globalValueSetTranslation-meta.xml' $GlobalValueSetTranslationPath $xmlString
            }
        }
    }
}