It returns Windows' 'canonical' locale identifier as well as the default keyboard layout.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/SetWinLocale.ps1 | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
diff --git a/testbot/bin/SetWinLocale.ps1 b/testbot/bin/SetWinLocale.ps1 index ed8fa29ee1..26bd03fdfd 100644 --- a/testbot/bin/SetWinLocale.ps1 +++ b/testbot/bin/SetWinLocale.ps1 @@ -103,6 +103,52 @@ function ShowSettings() exit 0 }
+function GetLocaleInfo($Locale) +{ + $LInfo= New-WinUserLanguageList $Locale + $LInfo = $LInfo[0] + + # Window synthesizes an Autonym for unknown/uninstalled locales (e.g. fr-DE), + # but cannot recommend a keyboard layout. + # Note also that installing a locale (e.g. fr-FR) typically also installs + # (at least the core functionality of) related locales (e.g. fr-BE), even + # though those are not shown as installed in the GUI. + if ($LInfo.InputMethodTips[0] -eq $null) + { + return $null + } + + # 'Canonicalize' the LanguageTag by picking the matching entry from the + # installed languages list. + $List = Get-WinUserLanguageList + foreach ($L in $List) + { + if ($LInfo.Autonym -eq $L.Autonym) + { + return $L + } + } + return $LInfo +} + + +function ShowLocaleInfo($Argv) +{ + $Locale = $Argv[1] +GetLocaleInfo($Locale) + $LInfo = GetLocaleInfo($Locale) + if ($LInfo -eq $null) + { + echo "$Name0:error: unknown locale $Locale. Is it installed?" + exit 1 + } + + Write-Output "LanguageTag=$($LInfo.LanguageTag)" + Write-Output "Autonym=$($LInfo.Autonym)" + Write-Output "LocalizedName=$($LInfo.LocalizedName)" + Write-Output "InputMethodTips=$($LInfo.InputMethodTips)" + exit 0 +}
# # Modify the Windows locales settings through intl.cpl @@ -309,6 +355,7 @@ function SetLocales($Argv) function ShowUsage() { Write-Output "Usage: $Name0 settings" + Write-Output "or $Name0 info LOCALE" Write-Output "or $Name0 intlconfig LOCALE COUNTRYID SYSTEM UTF8 MUI KEYBOARDID SYSCOPY DEFCOPY" Write-Output "or $Name0 locales LOCALE COUNTRYID SYSTEM UTF8 MUI KEYBOARDID SYSCOPY DEFCOPY USEINTLCPL" Write-Output "or $Name0 -?" @@ -317,6 +364,8 @@ function ShowUsage() Write-Output "" Write-Output "Where:" Write-Output " settings Show the current Windows locale settings." + Write-Output " info Show information about the specified locale. In particular it" + Write-Output " shows Windows' 'canonical' locale identifier." Write-Output " intlconfig Generates an XML configuration file for intl.cpl." Write-Output " locales Modifies the locales either through the Powershell APIs or" Write-Output " intl.cpl." @@ -341,6 +390,7 @@ function ShowUsage()
$Action = $args[0] if ($Action -eq "settings") { ShowSettings } +if ($Action -eq "info") { ShowLocaleInfo $args } if ($Action -eq "intlconfig") { ShowIntlConfig $args } if ($Action -eq "locales") { SetLocales $args } $Rc = 0
The Powershell API can provide information about locales related to the ones that have been installed which the registry does not. For instance after installing fr_FR one can also get the LCID and keyboard layout for fr_BE, fr_CH, etc. Add GetWinProperties() to standardize retrieving information from the SetWinLocale.ps1 script.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/SetWinLocale | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-)
diff --git a/testbot/bin/SetWinLocale b/testbot/bin/SetWinLocale index 29b57b30f8..73c774e6e4 100755 --- a/testbot/bin/SetWinLocale +++ b/testbot/bin/SetWinLocale @@ -43,7 +43,6 @@ use WineTestBot::Utils;
my $HKCU_INTERNATIONAL = "HKCU\Control Panel\International"; my $HKCU_GEO = "HKCU\Control Panel\International\Geo"; -my $HKCU_USER_PROFILE = "HKCU\Control Panel\International\User Profile";
# @@ -679,10 +678,11 @@ else FatalError("could not open '$0.ps1' for reading: $!\n"); }
-sub GetWinSettings() +sub GetWinProperties($) { - my $Cmd = ["powershell.exe", "-ExecutionPolicy", "ByPass", "-File", - "$name0.ps1", "settings"]; + my ($Cmd) = @_; + + Debug(Elapsed($Start), " Running: @$Cmd\n"); my $Ret = $TA->RunAndWait($Cmd, 0, 30, undef, "$name0.out", "$name0.out"); FatalError("failed to run @$Cmd: ", $TA->GetLastError(), "\n") if ($Ret < 0); my $Out = $TA->GetFileToString("$name0.out") if (!$Ret); @@ -705,6 +705,12 @@ sub GetWinSettings() return $Settings; }
+sub GetWinSettings() +{ + return GetWinProperties(["powershell.exe", "-ExecutionPolicy", "ByPass", + "-File", "$name0.ps1", "settings"]); +} + sub Value2Str($) { my ($Value) = @_; @@ -774,28 +780,10 @@ sub GetWinKeyboardIds($) { my ($Locale) = @_;
- # The locale information is sometimes stored in a key with a non-standard - # name, despite the standard locale name being used everywhere else! - my $Key = $LocaleInfoKeys{$Locale} || $Locale; - my $Values = RegGetValues("$HKCU_USER_PROFILE\$Key", "*:*"); - if (!%$Values) - { - $Key =~ s/-.*$//; - $Values = RegGetValues("$HKCU_USER_PROFILE\$Key", "*:*"); - } - - # Look for the locale's keyboard id(s). - my %WinLayouts; - foreach my $VName (keys %$Values) - { - # The value is the keyboard layout's preference order - $WinLayouts{hex($Values->{$VName})} = $VName if ($VName =~ /^[0-9A-F]{4}:/); - } - $WinKeyboardIds{$Locale} = %WinLayouts ? [] : $Keyboards{$Locale}; - foreach my $Index (sort { $a cmp $b } keys %WinLayouts) - { - push @{$WinKeyboardIds{$Locale}}, $WinLayouts{$Index}; - } + my $Info = GetWinProperties(["powershell.exe", "-ExecutionPolicy", "ByPass", + "-File", "$name0.ps1", "info", $Locale]); + $WinKeyboardIds{$Locale} = $Info->{InputMethodTips} ? [$Info->{InputMethodTips}] : $Keyboards{$Locale}; + Debug("WinKeyboardIds=", Value2Str($WinKeyboardIds{$Locale}), "\n"); if (!$WinKeyboardIds{$Locale}) { FatalError("could not find the $Locale LCID and keyboard ids. Maybe the locale is not installed?\n");