# DeployCenter - localize application text using the current WinPE language. $script:DeployCenterLocale = 'fr-FR' $script:DeployCenterText = @{} function Initialize-DeployCenterLocalization { [CmdletBinding()] param([AllowNull()][string]$CultureName = [Globalization.CultureInfo]::CurrentUICulture.Name) $culture = if ([string]::IsNullOrWhiteSpace($CultureName)) { 'fr-FR' } else { $CultureName } $localeName = if ($culture.StartsWith('fr', [StringComparison]::OrdinalIgnoreCase)) { 'fr-FR' } else { 'en-US' } $resourcePath = Join-Path $PSScriptRoot (Join-Path '..' (Join-Path 'Locales' ($localeName + '.psd1'))) $resourcePath = [IO.Path]::GetFullPath($resourcePath) if (-not (Test-Path -LiteralPath $resourcePath -PathType Leaf)) { throw "Localization resource not found: $resourcePath" } $resource = Import-PowerShellDataFile -LiteralPath $resourcePath $script:DeployCenterLocale = $localeName $script:DeployCenterText = $resource.Strings return $localeName } function Get-DeployCenterText { [CmdletBinding()] param( [Parameter(Mandatory=$true)][AllowEmptyString()][string]$Text, [AllowEmptyCollection()][object[]]$FormatArguments = @() ) $localized = $Text if ($script:DeployCenterText.ContainsKey($Text)) { $localized = [string]$script:DeployCenterText[$Text] } else { foreach ($key in @($script:DeployCenterText.Keys | Sort-Object { $_.Length } -Descending)) { if ($Text.StartsWith([string]$key, [StringComparison]::Ordinal)) { $localized = [string]$script:DeployCenterText[$key] + $Text.Substring(([string]$key).Length) break } } } if ($FormatArguments.Count -gt 0) { return [string]::Format([Globalization.CultureInfo]::CurrentCulture, $localized, $FormatArguments) } return $localized } function ConvertTo-DeployCenterLocalizedLogMessage { [CmdletBinding()] param([Parameter(Mandatory=$true)][AllowEmptyString()][string]$Message) return Get-DeployCenterText -Text $Message } Export-ModuleMember -Function Initialize-DeployCenterLocalization, Get-DeployCenterText, ConvertTo-DeployCenterLocalizedLogMessage