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

Code Quality: Conversion of strings with Toggle value to Show/Hide/Toggle using ICU syntax #15556

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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: 6 additions & 0 deletions src/Files.App/Actions/IAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ public interface IAction
/// </summary>
string Label { get; }

/// <summary>
/// A label for display in context menus and toolbars where a different representation of the label is required.
/// </summary>
string LabelSpec
=> Label;

/// <summary>
/// A brief description of what the action does.
/// It will be used as the command name in the command palette.
Expand Down
5 changes: 4 additions & 1 deletion src/Files.App/Actions/Show/ToggleInfoPaneAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ internal sealed class ToggleInfoPaneAction : ObservableObject, IToggleAction
private readonly InfoPaneViewModel viewModel;

public string Label
=> "ToggleInfoPane".GetLocalizedResource();
=> "ToggleInfoPane".GetLocalizedFormatResource();

public string LabelSpec
=> "ToggleInfoPane".GetLocalizedFormatResource(!IsOn);

public string Description
=> "ToggleInfoPaneDescription".GetLocalizedResource();
Expand Down
4 changes: 3 additions & 1 deletion src/Files.App/Data/Commands/ActionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public string Label

/// <inheritdoc/>
public string LabelWithHotKey
=> HotKeyText is null ? Label : $"{Label} ({HotKeyText})";
=> HotKeyText is null ? Action.LabelSpec : $"{Action.LabelSpec} ({HotKeyText})";

/// <inheritdoc/>
public string AutomationName
Expand Down Expand Up @@ -176,6 +176,7 @@ private void Action_PropertyChanging(object? sender, PropertyChangingEventArgs e
break;
case nameof(IToggleAction.IsOn) when IsToggle:
OnPropertyChanging(nameof(IsOn));
OnPropertyChanging(nameof(LabelWithHotKey));
break;
case nameof(IAction.IsExecutable):
OnPropertyChanging(nameof(IsExecutable));
Expand All @@ -194,6 +195,7 @@ private void Action_PropertyChanged(object? sender, PropertyChangedEventArgs e)
break;
case nameof(IToggleAction.IsOn) when IsToggle:
OnPropertyChanged(nameof(IsOn));
OnPropertyChanged(nameof(LabelWithHotKey));
break;
case nameof(IAction.IsExecutable):
OnPropertyChanged(nameof(IsExecutable));
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Extensions/MessageFormatExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static string GetLocalizedFormatResource(this string resourceKey, params
/// <returns>The formatted localized resource string.</returns>
public static string GetLocalizedFormatResource(this string resourceKey, params object[] values)
{
var pairs = values.Select((value, index) => new KeyValuePair<string, object?>(index.ToString(), value))
var pairs = values.Select((value, index) => new KeyValuePair<string, object?>(index.ToString(), (value is bool b) ? (b ? 1 : 0) : value))
.ToDictionary(pair => pair.Key, pair => pair.Value);
return GetLocalizedFormatResource(resourceKey, pairs);
}
Expand All @@ -126,6 +126,6 @@ public static string GetLocalizedFormatResource(this string resourceKey, params
/// </summary>
/// <param name="resourceKey">The key for the resource string.</param>
/// <returns>The localized resource string.</returns>
public static string GetLocalizedFormatResource(this string resourceKey) => GetLocalizedFormatResource(resourceKey, new Dictionary<string, object?>());
public static string GetLocalizedFormatResource(this string resourceKey) => GetLocalizedFormatResource(resourceKey, 0.ToFormatPairs(string.Empty));
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@
<value>Toggle the details pane to view basic file properties</value>
</data>
<data name="ToggleInfoPane" xml:space="preserve">
<value>Toggle the info pane</value>
<value>{0, select, 1 {Show} 0 {Hide} other {Toggle}} the info pane</value>
</data>
<data name="ToggleInfoPaneDescription" xml:space="preserve">
<value>Toggle the info pane to view the detail/preview panes</value>
Expand Down
Loading