Modules/businessdev.ALbuild.Containers/Private/Get-BcLanguageAppName.ps1
|
function Get-BcLanguageAppName { <# .SYNOPSIS Derives the name of Microsoft's language app for a culture, e.g. 'de-DE' -> 'German language (Germany)'. .DESCRIPTION Microsoft ships one app per UI language, named '<Language> language (<Region>)'. The name is taken from the culture's English name ('German (Germany)'), so every culture works without a lookup table. A neutral culture ('de') or an unknown one throws: neither names a language app. .PARAMETER Language A specific culture name, e.g. 'de-DE'. #> [CmdletBinding()] [OutputType([string])] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $Language ) $culture = $null try { $culture = [System.Globalization.CultureInfo]::GetCultureInfo($Language) } catch { throw "'$Language' is not a valid culture name. Pass a specific culture such as 'de-DE'." } # .NET on ICU accepts any well-formed tag and names it 'Unknown language (...)'. $english = "$($culture.EnglishName)" $parsed = [regex]::Match($english, '^(?<language>.+?) \((?<region>.+)\)$') if ($culture.IsNeutralCulture -or -not $parsed.Success -or $english -like 'Unknown*') { throw "'$Language' does not name a specific language and region ('$english'). Pass a specific culture such as 'de-DE'." } return "$($parsed.Groups['language'].Value) language ($($parsed.Groups['region'].Value))" } |