![英语(美国国际)的语言代码是什么?](https://linux22.com/image/1616257/%E8%8B%B1%E8%AF%AD%EF%BC%88%E7%BE%8E%E5%9B%BD%E5%9B%BD%E9%99%85%EF%BC%89%E7%9A%84%E8%AF%AD%E8%A8%80%E4%BB%A3%E7%A0%81%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F.png)
答案1
Param ( [parameter(Mandatory=$False)] [int16]$Out = 0 )
$regBase = 'Registry::' +
'HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layouts'
Function Get-Intl {
param( [string]$InputMethodTip )
$auxlang, $auxKeyb = $InputMethodTip -split ':'
$auxLangIn = [System.Globalization.CultureInfo]::
GetCultureInfo( [int]"0x$auxlang" ) # -band 0x3FF )
$KbdLayout = Get-ItemProperty -Path (
Join-Path -Path $regBase -ChildPath $auxKeyb
) -ErrorAction SilentlyContinue
if ( $KbdLayout.PsObject.Properties.Name -contains 'Layout Id' ) {
### ↓ unclear!
$LayoutId = "f$($KbdLayout.'Layout Id'.Substring(1))"
### ↑ incorrect!
} else {
$LayoutId = $auxKeyb.Substring(4)
}
$HKL = "$LayoutId$auxlang"
[psCustomObject]@{
HKL = $HKL
InputMethodTip = $InputMethodTip
Name = $auxLangIn.Name
# Autonym = $WinUserLanguage.Autonym
# DisplayName = $auxLangIn.DisplayName
KbdLayoutName = $KbdLayout.'Layout Text'
}
}
Switch ( ($Out % 3) )
{
0 {
Write-Verbose '--- Get-WinUserLanguageList output:' -Verbose
# $WinUserLanguageList = Get-WinUserLanguageList
# $LayoutsReal =
ForEach ( $WinUserLanguage in ( Get-WinUserLanguageList ) ) {
$WinUserLanguage.InputMethodTips | ForEach-Object {
Get-Intl -InputMethodTip $_
}
}
# $LayoutsReal
break
}
1 {
Write-Verbose '=== HKEY_USERS\.DEFAULT output:' -Verbose
$regDefa = 'Registry::' +
'HKEY_USERS\.DEFAULT\Control Panel\International\User Profile'
# HKEY_USERS\.DEFAULT\Control Panel\International\User Profile System Backup
# $LayoutsHkuD =
Get-ChildItem -Path $regDefa -Force |
Select-Object -ExpandProperty Property |
Where-Object { $_ -match ':' } |
ForEach-Object {
Get-Intl -InputMethodTip $_
}
# $LayoutsHkuD #| Sort-Object -Property Nane
break
}
4 {
Write-Verbose '--- DISM.exe output:' -Verbose
## DISM.exe /Online /Get-Intl
## gives following values in the 'Active keyboard(s)' line:
## '0809:00000405, 0405:00000405, 0405:00020409, 0408:00010408, 0419:00020419, 041b:0000041b, 041f:0000041f, 041f:00000426, 0425:00000425, 0425:00010409, 0809:00000452'
#
## but DISM.exe insists upon #requires -RunAsAdministrator
## hence, here are merely pasted&copied values:
$DismActiveKeyboards = '0809:00000405, 0405:00000405, 0405:00020409, 0408:00010408, 0419:00020419, 041b:0000041b, 041f:0000041f, 041f:00000426, 0425:00000425, 0425:00010409, 0809:00000452' -split ', '
# $LayoutsDism =
$DismActiveKeyboards |
ForEach-Object {
Get-Intl -InputMethodTip $_
}
# $LayoutsDism #| Sort-Object -Property Nane
break
}
default { Write-Verbose "$out = DISM.exe output isn't available as yet" -Verbose }
}
例子:D:\PShell\tests\InputMethodTip.ps1
VERBOSE: --- Get-WinUserLanguageList output: HKL InputMethodTip Name KbdLayoutName --- -------------- ---- ------------- 04050809 0809:00000405 en-GB Czech 04520809 0809:00000452 en-GB United Kingdom Extended 04050405 0405:00000405 cs-CZ Czech f0010405 0405:00020409 cs-CZ United States-International 04090405 0405:00000409 cs-CZ US f0020405 0405:00010409 cs-CZ United States-Dvorak f0160408 0408:00010408 el-GR Greek (220) f0330419 0419:00020419 ru-RU Russian - Mnemonic
脚本只是以Get-WinUserLanguageList
表格形式显示信息,扩展效果LayoutName
比混淆要好
if ( -not ("System.Windows.Forms.Form" -as [type]) ) {
Add-Type -AssemblyName System.Windows.Forms
}
[System.Windows.Forms.InputLanguage]::InstalledInputLanguages |
ForEach-Object { '{0} 0x{1:x8} {2}' -f $_.Culture,
($_.Handle -band 0xffffffff), $_.LayoutName
}
en-GB 0x04050809 Czech cs-CZ 0x04050405 Czech cs-CZ 0x04090405 US cs-CZ 0xf0020405 US cs-CZ 0xf0010405 US el-GR 0xf0160408 Greek (220) ru-RU 0xf0330419 Russian - Mnemonic en-GB 0x04520809 Czech
答案2
美国国际标准不是语言代码,而是一种输入法。因此,如果您想将 en-US(International) 键盘布局添加到某种语言,请使用如下方法:
$actualKB = Get-WinUserLanguageList
$actualKB[0].InputMethodTips.Add('0409:00020409') > #Add en-US(International)
Set-WinUserLanguageList $actualKB -Force
Set-WinDefaultInputMethodOverride -InputTip "0409:00000409" #set default keyboard en-US(International)
参考:
- https://learn.microsoft.com/en-us/powershell/module/international/set-windefaultinputmethodoverride?view=windowsserver2022-ps
- https://learn.microsoft.com/en-us/powershell/module/international/set-winuserlanguagelist?view=windowsserver2022-ps
- https://learn.microsoft.com/en-us/powershell/module/international/get-winuserlanguagelist?view=windowsserver2022-ps