You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Import-LocalizedData does not load any data when there is mismatch between current UI culture and data available #8219
This issue shows a regression as it works in Windows PowerShell but not PowerShell Core.
When Import-LocalizedData is used without specifying the UICulture explicitly but there is no language folder for it, then Windows PowerShell falls back to one that is available but PowerShell Core (6.1 and 6.1-preview) does not assign any variables and there is also no error/warning.
Steps to reproduce
I made an example hello-world repo here for your convenience
Expected behaviour
Import-LocalizedData could e.g.
fallback to an existing culture if there is no exact match
offer a parameter for a default culture if there is no match
log a warning instead of not doing anything
Actual behavior
The variable will not be bound if there is a mismatch and no warnings are given to the user, thus leading to bugs.
Yes, the module author could fix this, by writing some logic for a fallback language provider if there is no match but given that Windows PowerShell handled it nicely, this is a bit of a regression to me.
Environment data
>$PSVersionTable
Name Value
---------
PSVersion 6.2.0-preview.1
PSEdition Core
GitCommitId 6.2.0-preview.1
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Import-LocalizedData walks up the Parent property of either the CurrentUICulture or a supplied -UICulture. However, there is a difference in how the Parent properties are filled between .NET Framework and .NET Core (and higher).
This difference causes a problem for a reasonable number of the modules in System32 that make use of Import-LocalizedData. The list from my computer is below, not all of these are or can be compatible with Core, nor am I suggesting that any change here will make them so:
Then the parent of that culture is explored to try and find a path to import. With a UI culture of en-GB, I see the following parents:
PS>$culture= [System.Globalization.CultureInfo]::CurrentUICulture
PS>do { $culture.Name; $culture=$culture.Parent } while ($culture.Name)
en-GB
en
en-US
en
A spot check of a few other non-en-US UI cultures shows similar results, but I haven't looked hard enough to find a simple way to change the current UI culture to really prove that.
If I do the same in PowerShell 7 the parent of the first en is 127, Invariant Language (Invariant Country). That is, en-US and it's parent culture(s) are not in the list.
When I use the -UICulture parameter instead, Import-LocalizedData gets the CultureInfo object using Globalization.GetCultureInfo:
If I use PowerShell 6 or higher (7.3.4 for my testing), then I will instead receive an error because of the change in how .NET is exposing the Parent culture list for the CurrentUICulture.
In both cases, if use the -UICulture parameter explicitly (with my en-GB culture) then it will fail.
I think it can be said that:
This was a bug in .NET.
This is a bug in localization handling in each of the modules consuming Import-LocalizedData.
However, it can also be said that the bug in .NET has introduced a behaviour change between PowerShell 5.1 and 6+ and I would assert that it is reasonable to fix this problem in the Import-LocalizedData commmand.
I propose that when the -UICulture parameter is not supplied, that en-US should be added to the bottom of the list of parent cultures to search, restoring the behaviour of the command as it was in 5.1.
There is seemingly other issues as well. I am trying to make our powershell module cross platform (depends on a couple of COM objects), and this statement is working on Windows, but not on macOS.
The configuration.psd1 is located in the parent directory of the script and $__Session.Path.Root is the parent directory.
On Windows using Powershell Core 7.6.0 it loads the pds1 as expected.
On macOS using Powershell Core 7.6.0 if fails with the error Cannot find the PowerShell data file 'configurations.psd1' in directory '/Users/izaac.braann/Sources/our-module/sv-SE', or in any parent culture directories. Get-Culture renders the same information on both Windows and macOS.
Windows Pwsh:
Name Value
---- -----
PSVersion 7.6.0
PSEdition Core
GitCommitId 7.6.0
OS Microsoft Windows 10.0.26200
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.4
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
--------------------------------
LCID Name DisplayName
---- ---- -----------
1053 sv-SE Swedish (Sweden)
macOS Pwsh:
Name Value
---- -----
PSVersion 7.6.0
PSEdition Core
GitCommitId 7.6.0
OS macOS 26.4.1
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.4
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
--------------------------------
LCID Name DisplayName
---- ---- -----------
1053 sv-SE svenska (Sverige)
Activity
chrisdent-de commentedon Jun 15, 2023
Import-LocalizedDatawalks up the Parent property of either theCurrentUICultureor a supplied-UICulture. However, there is a difference in how theParentproperties are filled between .NET Framework and .NET Core (and higher).This difference causes a problem for a reasonable number of the modules in System32 that make use of
Import-LocalizedData. The list from my computer is below, not all of these are or can be compatible with Core, nor am I suggesting that any change here will make them so:Import-LocalizedDatauses the static propertyGlobalization.CurrentUICulturewhen a-UICultureis not supplied:[System.Globalization.CultureInfo]::CurrentUICultureThen the parent of that culture is explored to try and find a path to import. With a UI culture of
en-GB, I see the following parents:A spot check of a few other non-en-US UI cultures shows similar results, but I haven't looked hard enough to find a simple way to change the current UI culture to really prove that.
If I do the same in PowerShell 7 the parent of the first
enis 127,Invariant Language (Invariant Country). That is,en-USand it's parent culture(s) are not in the list.When I use the
-UICultureparameter instead,Import-LocalizedDatagets theCultureInfoobject usingGlobalization.GetCultureInfo:In both .NET Framework and .NET Core+,
en-USis not included in the parent culture list.Therefore, if my current culture is
en-GBand I run this command in Windows PowerShell it will successfully find the localization file:If I use PowerShell 6 or higher (7.3.4 for my testing), then I will instead receive an error because of the change in how .NET is exposing the Parent culture list for the CurrentUICulture.
In both cases, if use the
-UICultureparameter explicitly (with myen-GBculture) then it will fail.I think it can be said that:
Import-LocalizedData.However, it can also be said that the bug in .NET has introduced a behaviour change between PowerShell 5.1 and 6+ and I would assert that it is reasonable to fix this problem in the
Import-LocalizedDatacommmand.I propose that when the
-UICultureparameter is not supplied, thaten-USshould be added to the bottom of the list of parent cultures to search, restoring the behaviour of the command as it was in 5.1.IzaacJ commentedon Apr 13, 2026
There is seemingly other issues as well. I am trying to make our powershell module cross platform (depends on a couple of COM objects), and this statement is working on Windows, but not on macOS.
$__Session.Config = Import-LocalizedData -BaseDirectory $__Session.Path.Root -FileName 'configurations.psd1'The
configuration.psd1is located in the parent directory of the script and$__Session.Path.Rootis the parent directory.On Windows using Powershell Core 7.6.0 it loads the pds1 as expected.
On macOS using Powershell Core 7.6.0 if fails with the error
Cannot find the PowerShell data file 'configurations.psd1' in directory '/Users/izaac.braann/Sources/our-module/sv-SE', or in any parent culture directories.Get-Culturerenders the same information on both Windows and macOS.Windows Pwsh:
macOS Pwsh:
Very crude view of the related files and paths: