Francois Gouget : testbot/SetWinLocale: Add an 'info LOCALE' action to the Powershell script.

Alexandre Julliard julliard at winehq.org
Wed Feb 16 15:28:34 CST 2022


Module: tools
Branch: master
Commit: 7d57e9617f113529cc7b55313f0d7252391869f2
URL:    https://source.winehq.org/git/tools.git/?a=commit;h=7d57e9617f113529cc7b55313f0d7252391869f2

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Wed Feb 16 20:15:40 2022 +0100

testbot/SetWinLocale: Add an 'info LOCALE' action to the Powershell script.

It returns Windows' 'canonical' locale identifier as well as the default
keyboard layout.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 testbot/bin/SetWinLocale.ps1 | 50 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/testbot/bin/SetWinLocale.ps1 b/testbot/bin/SetWinLocale.ps1
index ed8fa29..26bd03f 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




More information about the wine-cvs mailing list