From c00e05b8657015e5b6e7ba711f3c4973336047a9 Mon Sep 17 00:00:00 2001 From: teramako Date: Sun, 7 Sep 2025 13:13:06 +0000 Subject: [PATCH 1/3] Fix Locale in Metadata for New-MarkdownCommandHelp --- src/Common/MetadataUtils.cs | 6 +++--- src/Transform/TransformBase.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Common/MetadataUtils.cs b/src/Common/MetadataUtils.cs index eebddbe3..34de6826 100644 --- a/src/Common/MetadataUtils.cs +++ b/src/Common/MetadataUtils.cs @@ -42,14 +42,14 @@ public static OrderedDictionary GetCommandHelpBaseMetadata(CommandHelp help) /// /// /// - public static OrderedDictionary GetCommandHelpBaseMetadataFromCommandInfo(CommandInfo commandInfo) + public static OrderedDictionary GetCommandHelpBaseMetadataFromCommandInfo(CommandInfo commandInfo, CultureInfo locale) { OrderedDictionary metadata = new() { { "document type", "cmdlet" }, { "title", commandInfo.Name }, { "Module Name", commandInfo.ModuleName }, - { "Locale", CultureInfo.CurrentCulture.Name == string.Empty ? "en-US" : CultureInfo.CurrentCulture.Name }, + { "Locale", string.IsNullOrEmpty(locale.Name) ? "en-US" : locale.Name }, { "PlatyPS schema version", "2024-05-01" }, // was schema { "HelpUri", GetHelpCodeMethods.GetHelpUri(new PSObject(commandInfo)) }, // was online version { "ms.date", DateTime.Now.ToString("MM/dd/yyyy") }, @@ -378,4 +378,4 @@ internal static OrderedDictionary DeserializeMetadataText(string metadataBlock) } } -} \ No newline at end of file +} diff --git a/src/Transform/TransformBase.cs b/src/Transform/TransformBase.cs index eb7f5068..9243af6c 100644 --- a/src/Transform/TransformBase.cs +++ b/src/Transform/TransformBase.cs @@ -55,8 +55,8 @@ protected CommandHelp ConvertCmdletInfo(CommandInfo? commandInfo) } CommandHelp cmdHelp = new(commandInfo.Name, commandInfo.ModuleName, Settings.Locale); - cmdHelp.Metadata = MetadataUtils.GetCommandHelpBaseMetadataFromCommandInfo(commandInfo); - cmdHelp.ExternalHelpFile = cmdHelp.Metadata["external help file"].ToString() ?? string.Empty; + cmdHelp.Metadata = MetadataUtils.GetCommandHelpBaseMetadataFromCommandInfo(commandInfo, Settings.Locale); + cmdHelp.ExternalHelpFile = cmdHelp.Metadata["external help file"] as string ?? string.Empty; cmdHelp.OnlineVersionUrl = Settings.OnlineVersionUrl ?? cmdHelp.Metadata["HelpUri"] as string; cmdHelp.SchemaVersion = cmdHelp.Metadata["PlatyPS schema version"] as string ?? string.Empty; cmdHelp.Synopsis = GetSynopsis(helpItem, addDefaultStrings); From 106f69987733ccb092d4d719a0b3eefa97662244 Mon Sep 17 00:00:00 2001 From: teramako Date: Mon, 8 Sep 2025 04:56:10 +0000 Subject: [PATCH 2/3] Add `-Locale` parameter test for New-MarkdownCommandHelp --- test/Pester/NewMarkdownHelp.Tests.ps1 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/Pester/NewMarkdownHelp.Tests.ps1 b/test/Pester/NewMarkdownHelp.Tests.ps1 index 20e242be..dbb797ff 100644 --- a/test/Pester/NewMarkdownHelp.Tests.ps1 +++ b/test/Pester/NewMarkdownHelp.Tests.ps1 @@ -683,4 +683,31 @@ Write-Host 'Hello World!' $commandHelp.Syntax[0].ToString() | Should -Not -Match 'Hidden|Break' } } + + Context 'Locale parameter' { + BeforeAll { + function global:Test-Locale { + [CmdletBinding()] + param() + } + } + + It 'No Locale parameter' { + $file = New-MarkdownCommandHelp -Command (Get-Command 'Test-Locale') -OutputFolder "$TestDrive/NewMarkdownHelp" -Force + + Get-Content -Path $file -First 10 | Where-Object { $_ -match "^Locale" } | Should -Be "Locale: en-US" + } + + It 'Invariant Locale parameter' { + $file = New-MarkdownCommandHelp -Command (Get-Command 'Test-Locale') -OutputFolder "$TestDrive/NewMarkdownHelp" -Force -Locale C + + Get-Content -Path $file -First 10 | Where-Object { $_ -match "^Locale" } | Should -Be "Locale: en-US" + } + + It 'ja-JP Locale parameter' { + $file = New-MarkdownCommandHelp -Command (Get-Command 'Test-Locale') -OutputFolder "$TestDrive/NewMarkdownHelp" -Force -Locale ja-JP + + Get-Content -Path $file -First 10 | Where-Object { $_ -match "^Locale" } | Should -Be "Locale: ja-JP" + } + } } From c2b95fe115eae55f6118a2ecdd1aefab57326265 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 8 Jul 2026 11:59:14 -0700 Subject: [PATCH 3/3] Fix invariant locale for test --- test/Pester/NewMarkdownHelp.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Pester/NewMarkdownHelp.Tests.ps1 b/test/Pester/NewMarkdownHelp.Tests.ps1 index 0a2dc126..b40bb255 100644 --- a/test/Pester/NewMarkdownHelp.Tests.ps1 +++ b/test/Pester/NewMarkdownHelp.Tests.ps1 @@ -738,7 +738,7 @@ Write-Host 'Hello World!' } It 'Invariant Locale parameter' { - $file = New-MarkdownCommandHelp -Command (Get-Command 'Test-Locale') -OutputFolder "$TestDrive/NewMarkdownHelp" -Force -Locale C + $file = New-MarkdownCommandHelp -Command (Get-Command 'Test-Locale') -OutputFolder "$TestDrive/NewMarkdownHelp" -Force -Locale ([System.Globalization.CultureInfo]::InvariantCulture).ToString() Get-Content -Path $file -First 10 | Where-Object { $_ -match "^Locale" } | Should -Be "Locale: en-US" }