Created
June 7, 2021 13:44
-
-
Save jhoek/f7a12cc2d8f730ab37695e238dcb9121 to your computer and use it in GitHub Desktop.
Convert-TextConstantToLabel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Convert-LanguageIdentifier | |
{ | |
param | |
( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[ValidatePattern('[A-Z]{3}')] | |
[string[]]$ThreeLetterWindowsLanguageName | |
) | |
$ThreeLetterWindowsLanguageName.ForEach{ | |
$CurrentLanguage = $_ | |
switch ($CurrentLanguage) | |
{ | |
'ENU' { return 'en-US' } | |
'NLD' { return 'nl-NL' } | |
'FRA' { return 'fr-FR' } | |
'ESP' { return 'es-ES' } | |
default { throw "Unanticipated language: $CurrentLanguage" } | |
} | |
} | |
} | |
<# | |
.EXAMPLE | |
Convert-TextConstantToLabel -TextConstant " Text_SP: TextConst ENU = 'sp.', FRA = 'sp.', NLD = 'sp.';" | |
#> | |
function Convert-TextConstantToLabel | |
{ | |
param | |
( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[string[]]$TextConstant, | |
[ValidateNotNullOrEmpty()] | |
[string]$DeveloperNoteSeparator = '|' | |
) | |
process | |
{ | |
$TextConstant.ForEach{ | |
$Name, $ValuesAsText = $_ -split ':',2 | |
Write-Verbose "Name: '$Name'" | |
$ValuesAsText = $ValuesAsText -replace '^\s*TextConst', '' -replace ';$', '' | |
Write-Verbose "ValuesAsText: '$ValuesAsText'" | |
$ValuesArray = $ValuesAsText -split ',' | |
Write-Verbose "ValuesArray:" | |
Write-Verbose ($ValuesArray -join "`n") | |
$Values = $ValuesArray | ForEach-Object { | |
$Language, $Value = $_ -split '=',2 | |
$Result = [PSCustomObject]@{ | |
Language = $Language.Trim() | Convert-LanguageIdentifier | |
Value = $Value.Trim() -replace '^''(.*)''$', '$1' | |
} | |
Write-Verbose "$($Result.Language): '$($Result.Value)'" | |
$Result | |
} | |
"$($Name): Label $($Values | Where-Object Language -eq 'en-US' | ForEach-Object { "'$($_.Value)'"}), Comment = '$($Values | Where-Object Language -ne 'en-US' | ForEach-Object { "$($_.Language)=$($_.Value)" } | Join-String -Separator $DeveloperNoteSeparator )';" | |
# Text_SP: TextConst ENU = 'sp.', FRA = 'sp.', NLD = 'sp.'; | |
# Text_SP: Label 'sp.', Comment = 'fr-FR=sp.|nl-NL=sp.'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment