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 421ef31b..1c798372 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);
diff --git a/test/Pester/NewMarkdownHelp.Tests.ps1 b/test/Pester/NewMarkdownHelp.Tests.ps1
index 3e73be77..b40bb255 100644
--- a/test/Pester/NewMarkdownHelp.Tests.ps1
+++ b/test/Pester/NewMarkdownHelp.Tests.ps1
@@ -722,4 +722,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 ([System.Globalization.CultureInfo]::InvariantCulture).ToString()
+
+ 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"
+ }
+ }
}