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
6 changes: 3 additions & 3 deletions src/Common/MetadataUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public static OrderedDictionary GetCommandHelpBaseMetadata(CommandHelp help)
/// </summary>
/// <param name="commandInfo"></param>
/// <returns></returns>
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") },
Expand Down Expand Up @@ -378,4 +378,4 @@ internal static OrderedDictionary DeserializeMetadataText(string metadataBlock)
}
}

}
}
4 changes: 2 additions & 2 deletions src/Transform/TransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 27 additions & 0 deletions test/Pester/NewMarkdownHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}