Skip to content

Commit

Permalink
Add check for no UI language in the current culture (linux C.UTF-8) t…
Browse files Browse the repository at this point in the history
…o show appropiate message when calling Update-Help
  • Loading branch information
josea committed Jun 7, 2023
1 parent b159db3 commit 034c974
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/System.Management.Automation/help/UpdateHelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Help;
using System.Management.Automation.Internal;
Expand Down Expand Up @@ -181,6 +182,15 @@ protected override void ProcessRecord()

_isInitialized = true;
}

// check if there is an UI, if not Throw out terminating error.
var cultures = _language ?? _helpSystem.GetCurrentUICulture();
if (!cultures.Any())
{
string errMsg = StringUtil.Format(HelpDisplayStrings.FailedToUpdateHelpWithCUTF8Culture);
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "UILanguageNotSpecifiedInCulture", ErrorCategory.InvalidOperation, null);
ThrowTerminatingError(error);
}

base.Process(_module, FullyQualifiedModule);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ English-US help content is available and can be saved using: Save-Help -UICultur
<value>Failed to update Help for the module(s) '{0}' with UI culture(s) {{{1}}} : {2}.
English-US help content is available and can be installed using: Update-Help -UICulture en-US.</value>
</data>
<data name="FailedToUpdateHelpWithCUTF8Culture" xml:space="preserve">
<value>Your culture is C.UTF-8, which is a default not associated with any language, consider changing your system culture or install the English-US help content using: Update-Help -UICulture en-US.</value>
</data>
<data name="FalseShort" xml:space="preserve">
<value>false</value>
</data>
Expand Down
15 changes: 15 additions & 0 deletions test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,12 @@ Describe "Validate 'Update-Help' shows 'HelpCultureNotSupported' when thrown" -T
@{ 'name' = 'explicit culture de-DE'; 'culture' = 'de-DE' }
) {
param ($name, $culture)

# if running in Linux as an invariant culture => force Spanish
if ($IsLinux && $culture -eq $null && (Get-Culture).LCID -eq 127 ){
$culture = 'es-ES'
}

# Cannot pass null, have to splat to skip argument entirely
$cultureArg = $culture ? @{ 'UICulture' = $culture } : @{}
$cultureUsed = $culture ?? (Get-Culture)
Expand All @@ -431,6 +437,15 @@ Describe "Validate 'Update-Help' shows 'HelpCultureNotSupported' when thrown" -T
}
}

Describe "Validate 'Update-Help' shows 'UILanguageNotSpecifiedInCulture' when no language in culture" -Tags @('Feature') {

It 'Shows error if culture not specified in a linux system with C.UTF-8:' -Skip:(($IsLinux -eq $false) || ((Get-Culture).LCID -ne 127)) {
{
Update-Help -ErrorAction SilentlyContinue
} | Should -Throw "Your culture is C.UTF-8, which is a default not associated with any language, consider changing your system culture or install the English-US help content using: Update-Help -UICulture en-US."
}
}

Describe "Validate 'Save-Help -DestinationPath for one PowerShell modules." -Tags @('CI', 'RequireAdminOnWindows') {
BeforeAll {
$SavedProgressPreference = $ProgressPreference
Expand Down

0 comments on commit 034c974

Please sign in to comment.