Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/CultureVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override object Value
get
{
DebuggerCheckVariableRead();
return System.Globalization.CultureInfo.CurrentCulture.Name;
return System.Threading.Thread.CurrentThread.CurrentCulture.Name;
}
}
}
Expand All @@ -52,7 +52,7 @@ public override object Value
get
{
DebuggerCheckVariableRead();
return System.Globalization.CultureInfo.CurrentUICulture.Name;
return System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/SessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ internal void InitializeFixedVariables()

// $PSCulture
v = new PSCultureVariable();
this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);
this.GlobalScope.SetVariableForce(v, this);

// $PSUICulture
v = new PSUICultureVariable();
this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);
this.GlobalScope.SetVariableForce(v, this);

// $?
v = new QuestionMarkVariable(this.ExecutionContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,46 @@ Describe "Get-Culture" -Tags "CI" {

Describe "`$PSCulture" -Tags "CI" {

It "Check `$PSCulture value" {
$PSCulture | Should -BeExactly $([System.Globalization.CultureInfo]::CurrentCulture.Name)
It "`$PSCulture is the current thread culture" {
$PSCulture | Should -BeExactly $([System.Threading.Thread]::CurrentThread.CurrentCulture.Name)
}

It "`$PSUICulture is the current thread culture" {
$PSUICulture | Should -BeExactly $([System.Threading.Thread]::CurrentThread.CurrentUICulture.Name)
}

It "`$PSCulture follows the current thread culture" {
$oldCulture = [CultureInfo]::CurrentCulture
$newCulture = "ru-RU"

# Workaround to pass tests locally
if ($oldCulture -eq "ru-RU") {
$newCulture = "fr-FR"
}

try {
[CultureInfo]::currentculture = $newCulture
$PSCulture | Should -BeExactly $newCulture
$PSCulture | Should -BeExactly $([System.Threading.Thread]::CurrentThread.CurrentCulture.Name)
} finally {
[CultureInfo]::CurrentCulture = $oldCulture
}
}

It "`$PSUICulture follows the current thread culture" {
$oldUICulture = [CultureInfo]::CurrentUICulture
$newUICulture = "ru-RU"

if ($oldUICulture -eq "ru-RU") {
$newUICulture = "fr-FR"
}

try {
[CultureInfo]::CurrentUICulture = $newUICulture
$PSUICulture | Should -BeExactly $newUICulture
$PSUICulture | Should -BeExactly $([System.Threading.Thread]::CurrentThread.CurrentUICulture.Name)
} finally {
[CultureInfo]::CurrentUICulture = $oldUICulture
}
}
}