Use Localization for Explorer plugin

This commit is contained in:
VictoriousRaptor 2025-07-16 21:28:17 +08:00
parent e116668ef9
commit 30f7ae0d67
12 changed files with 93 additions and 108 deletions

View file

@ -1,25 +0,0 @@
using Flow.Launcher.Plugin.Everything.Everything;
using JetBrains.Annotations;
using System;
namespace Flow.Launcher.Plugin.Explorer.Helper;
public static class SortOptionTranslationHelper
{
[CanBeNull]
public static IPublicAPI API { get; internal set; }
public static string GetTranslatedName(this SortOption sortOption)
{
const string prefix = "flowlauncher_plugin_everything_sort_by_";
ArgumentNullException.ThrowIfNull(API);
var enumName = Enum.GetName(sortOption);
var splited = enumName!.Split('_');
var name = string.Join('_', splited[..^1]);
var direction = splited[^1];
return $"{API.GetTranslation(prefix + name.ToLower())} {API.GetTranslation(prefix + direction.ToLower())}";
}
}

View file

@ -143,20 +143,33 @@
<system:String x:Key="flowlauncher_plugin_everything_is_not_running">Warning: Everything service is not running</system:String>
<system:String x:Key="flowlauncher_plugin_everything_query_error">Error while querying Everything</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by">Sort By</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_name">Name</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_path">Path</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_size">Size</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_extension">Extension</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_type_name">Type Name</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_created">Date Created</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_modified">Date Modified</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_attributes">Attributes</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_file_list_filename">File List FileName</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_run_count">Run Count</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_recently_changed">Date Recently Changed</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_accessed">Date Accessed</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_run">Date Run</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_ascending">&#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_name_ascending">Name &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_name_descending">Name &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_path_ascending">Path &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_path_descending">Path &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_size_ascending">Size &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_size_descending">Size &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_extension_ascending">Extension &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_extension_descending">Extension &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_type_name_ascending">Type Name &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_type_name_descending">Type Name &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_created_ascending">Date Created &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_created_descending">Date Created &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_modified_ascending">Date Modified &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_modified_descending">Date Modified &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_attributes_ascending">Attributes &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_attributes_descending">Attributes &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_file_list_filename_ascending">File List FileName &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_file_list_filename_descending">File List FileName &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_run_count_ascending">Run Count &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_run_count_descending">Run Count &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_recently_changed_ascending">Date Recently Changed &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_recently_changed_descending">Date Recently Changed &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_accessed_ascending">Date Accessed &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_accessed_descending">Date Accessed &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_run_ascending">Date Run &#x2191;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_run_descending">Date Run &#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_ascending">¡ü</system:String>
<system:String x:Key="flowlauncher_plugin_everything_sort_by_descending">&#x2193;</system:String>
<system:String x:Key="flowlauncher_plugin_everything_nonfastsort_warning">Warning: This is not a Fast Sort option, searches may be slow</system:String>

View file

@ -42,8 +42,6 @@ namespace Flow.Launcher.Plugin.Explorer
contextMenu = new ContextMenu(Context, Settings, viewModel);
searchManager = new SearchManager(Settings, Context);
ResultManager.Init(Context, Settings);
SortOptionTranslationHelper.API = context.API;
EverythingApiDllImport.Load(Path.Combine(Context.CurrentPluginMetadata.PluginDirectory, "EverythingSDK",
Environment.Is64BitProcess ? "x64" : "x86"));

View file

@ -1,5 +1,4 @@
using Flow.Launcher.Plugin.Everything.Everything;
using Flow.Launcher.Plugin.Explorer.Search.Everything.Exceptions;
using Flow.Launcher.Plugin.Explorer.Search.Everything.Exceptions;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
@ -36,7 +35,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
/// <summary>
/// Checks whether the sort option is Fast Sort.
/// </summary>
public static bool IsFastSortOption(SortOption sortOption)
public static bool IsFastSortOption(EverythingSortOption sortOption)
{
var fastSortOptionEnabled = EverythingApiDllImport.Everything_IsFastSort(sortOption);
@ -112,7 +111,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
EverythingApiDllImport.Everything_SetSort(option.SortOption);
EverythingApiDllImport.Everything_SetMatchPath(option.IsFullPathSearch);
if (option.SortOption == SortOption.RUN_COUNT_DESCENDING)
if (option.SortOption == EverythingSortOption.RUN_COUNT_DESCENDING)
{
EverythingApiDllImport.Everything_SetRequestFlags(EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME | EVERYTHING_REQUEST_RUN_COUNT);
}

View file

@ -1,5 +1,4 @@
using Flow.Launcher.Plugin.Everything.Everything;
using System;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
@ -114,11 +113,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
// Everything 1.4
[DllImport(DLL)]
public static extern void Everything_SetSort(SortOption dwSortType);
public static extern void Everything_SetSort(EverythingSortOption dwSortType);
[DllImport(DLL)]
public static extern bool Everything_IsFastSort(SortOption dwSortType);
public static extern bool Everything_IsFastSort(EverythingSortOption dwSortType);
[DllImport(DLL)]
public static extern SortOption Everything_GetSort();
public static extern EverythingSortOption Everything_GetSort();
[DllImport(DLL)]
public static extern uint Everything_GetResultListSort();
[DllImport(DLL)]

View file

@ -1,10 +1,8 @@
using Flow.Launcher.Plugin.Everything.Everything;
namespace Flow.Launcher.Plugin.Explorer.Search.Everything
namespace Flow.Launcher.Plugin.Explorer.Search.Everything
{
public record struct EverythingSearchOption(
string Keyword,
SortOption SortOption,
EverythingSortOption SortOption,
bool IsContentSearch = false,
string ContentSearchKeyword = default,
string ParentPath = default,

View file

@ -1,31 +1,59 @@
namespace Flow.Launcher.Plugin.Everything.Everything
using Flow.Launcher.Localization.Attributes;
namespace Flow.Launcher.Plugin.Explorer.Search.Everything
{
public enum SortOption : uint
[EnumLocalize]
public enum EverythingSortOption : uint
{
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_name_ascending))]
NAME_ASCENDING = 1u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_name_descending))]
NAME_DESCENDING = 2u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_path_ascending))]
PATH_ASCENDING = 3u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_path_descending))]
PATH_DESCENDING = 4u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_size_ascending))]
SIZE_ASCENDING = 5u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_size_descending))]
SIZE_DESCENDING = 6u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_extension_ascending))]
EXTENSION_ASCENDING = 7u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_extension_descending))]
EXTENSION_DESCENDING = 8u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_type_name_ascending))]
TYPE_NAME_ASCENDING = 9u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_type_name_descending))]
TYPE_NAME_DESCENDING = 10u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_date_created_ascending))]
DATE_CREATED_ASCENDING = 11u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_date_created_descending))]
DATE_CREATED_DESCENDING = 12u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_date_modified_ascending))]
DATE_MODIFIED_ASCENDING = 13u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_date_modified_descending))]
DATE_MODIFIED_DESCENDING = 14u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_attributes_ascending))]
ATTRIBUTES_ASCENDING = 15u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_attributes_descending))]
ATTRIBUTES_DESCENDING = 16u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_file_list_filename_ascending))]
FILE_LIST_FILENAME_ASCENDING = 17u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_file_list_filename_descending))]
FILE_LIST_FILENAME_DESCENDING = 18u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_run_count_descending))]
RUN_COUNT_DESCENDING = 20u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_date_recently_changed_ascending))]
DATE_RECENTLY_CHANGED_ASCENDING = 21u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_date_recently_changed_descending))]
DATE_RECENTLY_CHANGED_DESCENDING = 22u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_date_accessed_ascending))]
DATE_ACCESSED_ASCENDING = 23u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_date_accessed_descending))]
DATE_ACCESSED_DESCENDING = 24u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_date_run_ascending))]
DATE_RUN_ASCENDING = 25u,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_everything_sort_by_date_run_descending))]
DATE_RUN_DESCENDING = 26u
}
}

View file

@ -1,5 +1,4 @@
using Flow.Launcher.Plugin.Everything.Everything;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.Everything;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex;
@ -145,10 +144,7 @@ namespace Flow.Launcher.Plugin.Explorer
public string EverythingInstalledPath { get; set; }
[JsonIgnore]
public SortOption[] SortOptions { get; set; } = Enum.GetValues<SortOption>();
public SortOption SortOption { get; set; } = SortOption.NAME_ASCENDING;
public EverythingSortOption SortOption { get; set; } = EverythingSortOption.NAME_ASCENDING;
public bool EnableEverythingContentSearch { get; set; } = false;

View file

@ -35,6 +35,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
InitializeEngineSelection();
InitializeActionKeywordModels();
EverythingSortOptionLocalized.UpdateLabels(AllEverythingSortOptions);
}
public void Save()
@ -578,6 +579,20 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
#region Everything FastSortWarning
public List<EverythingSortOptionLocalized> AllEverythingSortOptions { get; } = EverythingSortOptionLocalized.GetValues();
public EverythingSortOption SelectedEverythingSortOption
{
get => Settings.SortOption;
set
{
Settings.SortOption = value;
OnPropertyChanged(nameof(SelectedEverythingSortOption));
OnPropertyChanged(nameof(FastSortWarningVisibility));
OnPropertyChanged(nameof(SortOptionWarningMessage));
}
}
public Visibility FastSortWarningVisibility
{
get
@ -607,15 +622,15 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
// this method is used to determine if Everything service is running because as at Everything v1.4.1
// the sdk does not provide a dedicated interface to determine if it is running.
return EverythingApi.IsFastSortOption(Settings.SortOption) ? string.Empty
: Context.API.GetTranslation("flowlauncher_plugin_everything_nonfastsort_warning");
: Localize.flowlauncher_plugin_everything_nonfastsort_warning();
}
catch (IPCErrorException)
{
return Context.API.GetTranslation("flowlauncher_plugin_everything_is_not_running");
return Localize.flowlauncher_plugin_everything_is_not_running();
}
catch (DllNotFoundException)
{
return Context.API.GetTranslation("flowlauncher_plugin_everything_sdk_issue");
return Localize.flowlauncher_plugin_everything_sdk_issue();
}
}
}

View file

@ -1,20 +0,0 @@
using Flow.Launcher.Plugin.Everything.Everything;
using Flow.Launcher.Plugin.Explorer.Helper;
using System;
using System.Globalization;
using System.Windows.Data;
namespace Flow.Launcher.Plugin.Explorer.Views.Converters;
public class EnumNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value is SortOption option ? option.GetTranslatedName() : value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

View file

@ -2,7 +2,6 @@
x:Class="Flow.Launcher.Plugin.Explorer.Views.ExplorerSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:Flow.Launcher.Plugin.Explorer.Views.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:qa="clr-namespace:Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks"
@ -74,8 +73,6 @@
</Grid>
</DataTemplate>
<converters:EnumNameConverter x:Key="EnumNameConverter" />
<Style x:Key="CustomExpanderStyle" TargetType="Expander">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="Background" Value="Transparent" />
@ -631,16 +628,10 @@
Grid.Column="1"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
VerticalAlignment="Center"
ItemsSource="{Binding Settings.SortOptions, Mode=OneWay}"
SelectedItem="{Binding Settings.SortOption}"
SelectionChanged="EverythingSortOptionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Converter={StaticResource EnumNameConverter}}" />
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
ItemsSource="{Binding AllEverythingSortOptions}"
SelectedValue="{Binding SelectedEverythingSortOption, Mode=TwoWay}"
SelectedValuePath="Value"
DisplayMemberPath="Display">
</ComboBox>
<TextBlock
@ -666,10 +657,10 @@
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
VerticalAlignment="Center"
Foreground="Orange"
Text="{Binding SortOptionWarningMessage, Mode=OneTime}"
Text="{Binding SortOptionWarningMessage, Mode=OneWay}"
TextAlignment="Left"
TextWrapping="Wrap"
Visibility="{Binding FastSortWarningVisibility, Mode=OneTime}" />
Visibility="{Binding FastSortWarningVisibility, Mode=OneWay}" />
</Grid>
</Expander>

View file

@ -77,14 +77,7 @@ namespace Flow.Launcher.Plugin.Explorer.Views
{
SettingsViewModel.OpenWindowsIndexingOptions();
}
private void EverythingSortOptionChanged(object sender, SelectionChangedEventArgs e)
{
if (tbFastSortWarning is not null)
{
tbFastSortWarning.Visibility = _viewModel.FastSortWarningVisibility;
tbFastSortWarning.Text = _viewModel.SortOptionWarningMessage;
}
}
private void LbxAccessLinks_OnDrop(object sender, DragEventArgs e)
{
AccessLinkDragDrop("QuickAccessLink", e);