Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-LocalizedData: Fails to import .strings.psd1 in 'en-US' folder on 'de-DE' operating system when default culture is 'en-US' #50

Closed
johlju opened this issue Jul 20, 2020 · 1 comment · Fixed by #51
Labels
bug The issue is a bug.

Comments

@johlju
Copy link
Member

johlju commented Jul 20, 2020

Details of the scenario you tried and the problem that is occurring

The issue is that the cmdlet defaults to the filename ModuleName.psd1 if the FIleName parameter is not set. When the default culture is set there are no evaluation which .psd1 name to import in the following code:

if (!$languageFile)
{
$PSBoundParameters.Add('UICulture', $DefaultUICulture)
}

Steps to reproduce the problem

This is a unit test that repro the issue:

            <#
                Regression test for issues loading the *.strings.psd1 from default
                culture when OS has different culture for which no localized strings
                exist.
            #>
            Context "When the operating system UI culture does not exist and the default culture have a '.strings.psd1' file" {
                BeforeAll {
                    New-Item -Force -Path 'TestDrive:\en-US' -ItemType Directory

                    # This content is written to the file 'en-US\Get-LocalizedData.Tests.strings.psd1'.
                    $null = "
ConvertFrom-StringData @`'
# sv-SE strings
StringKey    = String value
'@
                    " | Out-File -Force -FilePath 'TestDrive:\en-US\Get-LocalizedData.Tests.strings.psd1'

                    # Mocking German UICulture for which there are no localization strings.
                    Mock -CommandName Get-UICulture -MockWith {
                        return @{
                            Parent                         = 'de'
                            LCID                           = '1031'
                            KeyboardLayoutId               = '1031'
                            Name                           = 'de-DE'
                            IetfLanguageTag                = 'de-DE'
                            DisplayName                    = 'Deutsch (Deutschland)'
                            NativeName                     = 'Deutsch (Deutschland)'
                            EnglishName                    = 'German (Germany)'
                            TwoLetterISOLanguageName       = 'de'
                            ThreeLetterISOLanguageName     = 'deu'
                            ThreeLetterWindowsLanguageName = 'DEU'
                        }
                    }
                }

                It 'Should retrieve the data' {
                    { Get-LocalizedData -DefaultUICulture 'en-US' -BaseDirectory 'TestDrive:\'  } | Should -Not -Throw
                }
            }

Throws an error with the current code (added verbose messages to verify the mocks worked as expected):

      Context When the operating system UI culture does not exist and the default culture have a '.strings.psd1' file
VERBOSE: DEBUG 5: UICulture de-DE
VERBOSE: DEBUG 10: $PSBoundParameters.UICulture: en-US
VERBOSE: DEBUG 10: $PSBoundParameters.FileName: Get-LocalizedData.Tests.ps1
Import-LocalizedData: C:\source\DscResource.Common\tests\Unit\Public\Get-LocalizedData.Tests.ps1:189
Line |
 189 |  …           { Get-LocalizedData -DefaultUICulture 'en-US' -BaseDirector …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find the PowerShell data file 'Get-LocalizedData.Tests.psd1' in directory
     | 'C:\Users\johan.ljunggren\AppData\Local\Temp\17a66d67-279a-456c-b20c-af4c5f313c7a\en-US', or in any parent culture directories.

Expected behavior

Should import the correct file in en en-US folder.

Current behavior

Fails with an error it cannot load '*.psd1' (because there are no such file, there do exist a `*.strings.psd1').

Suggested solution to the issue

When there are no parent culture ($null -eq $currentCulture.Parent) the default culture should be set and the loop that evaluates the localization filenames should run one more time for the default culture.

The operating system the target node is running

Any

Version and build of PowerShell the target node is running

Any

Version of the module that was used

latest release

@johlju johlju changed the title Get-LocalizedData: Fails to import .strings.psd1 in 'en-US' folder on non-'en-US' operating system when default culture is 'en-US' Get-LocalizedData: Fails to import .strings.psd1 in 'en-US' folder on 'de-DE' operating system when default culture is 'en-US' Jul 20, 2020
@johlju johlju added bug The issue is a bug. in progress The issue is being actively worked on by someone. labels Jul 20, 2020
@PlagueHO
Copy link
Member

Well done @johlju !!!

@johlju johlju removed the in progress The issue is being actively worked on by someone. label Jul 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants