Created
March 23, 2021 13:00
-
-
Save jhoek/de66fa2f7f9311c49e6c5ce0ac5b8626 to your computer and use it in GitHub Desktop.
BC: Convert-TextConstant to Label
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