powershell:改变当前会话的文化

发布于 2024-11-29 08:11:38 字数 105 浏览 1 评论 0原文

我在 windows vista 上使用 powershell。 如何改变当前会话的文化? 我的计算机的文化是 tr-TR,所以我收到土耳其语的错误消息。我想改成EN?

有机会吗?

I am using powershell on windows vista.
How do I change the culture of current session?
My computer's culture is tr-TR so I am getting the error messages on Turkish. I would like to change to EN?

any chance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挽清梦 2024-12-06 08:11:38

请查看此处:http://blogs.msdn。 com/b/powershell/archive/2006/04/25/583235.aspx

和此处:http://poshcode.org/2226

function Set-Culture([System.Globalization.CultureInfo] $culture)
{
    [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
}

其他信息

要查找哪些值可用于$culture

  • 这将为您提供文化类型列表:

    [Enum]::GetValues([System.Globalization.CultureTypes])
    
  • 选择上述类型之一(例如 AllCultures),然后您可以列出该类型的可用值:

    [System.Globalization.CultureInfo]::GetCultures( [System.Globalization.CultureTypes]::AllCultures )
    
  • 然后您可以将您感兴趣的文化的名称或编号与GetCultureInfo 方法来检索您想要的值:

    $culture = [System.Globalization.CultureInfo]::GetCultureInfo(1033)
    $culture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
    

注意:感谢隐式转换,您可以将区域性名称或数字(即作为字符串或整数)传递给 Set-Culture 方法,该方法会自动转换为预期的 CultureInfo 值。

Have a look here: http://blogs.msdn.com/b/powershell/archive/2006/04/25/583235.aspx

and here: http://poshcode.org/2226:

function Set-Culture([System.Globalization.CultureInfo] $culture)
{
    [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
}

Additional Info

To find which values can be used for $culture:

  • This will give you a list of Culture Types:

    [Enum]::GetValues([System.Globalization.CultureTypes])
    
  • Selecting one of the above types (e.g. AllCultures) you can then list the available values of that type:

    [System.Globalization.CultureInfo]::GetCultures( [System.Globalization.CultureTypes]::AllCultures )
    
  • You can then use the Name or Number of the culture you're interested in with the GetCultureInfo method to retrieve the value you're after:

    $culture = [System.Globalization.CultureInfo]::GetCultureInfo(1033)
    $culture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
    

NB: Thanks to implicit conversion, you could just pass the culture name or number (i.e. as a string or integer) to the Set-Culture method which would automatically be converted to the expected CultureInfo value.

感情废物 2024-12-06 08:11:38

由于 @manojlds 接受的解决方案实际上不起作用(Windows 10 上的 PS 5.1),这里对我有用的解决方案(在

$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture("en-US")
$assembly = [System.Reflection.Assembly]::Load("System.Management.Automation")
$type = $assembly.GetType("Microsoft.PowerShell.NativeCultureResolver")
$field = $type.GetField("m_uiCulture", [Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Static)
$field.SetValue($null, $culture)

As the accepted solution by @manojlds actually doesn't work (PS 5.1 on Windows 10) here what works for me (found on github):

$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture("en-US")
$assembly = [System.Reflection.Assembly]::Load("System.Management.Automation")
$type = $assembly.GetType("Microsoft.PowerShell.NativeCultureResolver")
$field = $type.GetField("m_uiCulture", [Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Static)
$field.SetValue($null, $culture)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文