Skip to content

Commit 78e5bf2

Browse files
committed
Use Flow.Launcher.Localization to improve code quality
1 parent a2c11af commit 78e5bf2

File tree

16 files changed

+134
-153
lines changed

16 files changed

+134
-153
lines changed

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104

105105
<ItemGroup>
106106
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
107-
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.5" />
107+
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
108108
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.9" />
109109
<PackageReference Include="Svg.Skia" Version="3.0.6" />
110110
<PackageReference Include="SkiaSharp" Version="3.119.0" />

Plugins/Flow.Launcher.Plugin.Calculator/Flow.Launcher.Plugin.Calculator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
</ItemGroup>
6464

6565
<ItemGroup>
66-
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.5" />
66+
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
6767
<PackageReference Include="Mages" Version="3.0.0" />
6868
</ItemGroup>
6969

Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs

Lines changed: 52 additions & 62 deletions
Large diffs are not rendered by default.

Plugins/Flow.Launcher.Plugin.Explorer/Flow.Launcher.Plugin.Explorer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<ItemGroup>
4949
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
5050
<PackageReference Include="Droplex" Version="1.7.0" />
51-
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.5" />
51+
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
5252
<PackageReference Include="System.Data.OleDb" Version="9.0.9" />
5353
<PackageReference Include="System.Linq.Async" Version="6.0.3" />
5454
<PackageReference Include="tlbimp-Microsoft.Search.Interop" Version="1.0.0" />

Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<system:String x:Key="plugin_explorer_directoryinfosearch_error">Error occurred during search: {0}</system:String>
2525
<system:String x:Key="plugin_explorer_opendir_error">Could not open folder</system:String>
2626
<system:String x:Key="plugin_explorer_openfile_error">Could not open file</system:String>
27+
<system:String x:Key="plugin_explorer_new_action_keyword_assigned">This new action keyword is already assigned to another plugin, please choose a different one</system:String>
2728

2829
<!-- Controls -->
2930
<system:String x:Key="plugin_explorer_delete">Delete</system:String>

Plugins/Flow.Launcher.Plugin.Explorer/Main.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
9090

9191
public string GetTranslatedPluginTitle()
9292
{
93-
return Context.API.GetTranslation("plugin_explorer_plugin_name");
93+
return Localize.plugin_explorer_plugin_name();
9494
}
9595

9696
public string GetTranslatedPluginDescription()
9797
{
98-
return Context.API.GetTranslation("plugin_explorer_plugin_description");
98+
return Localize.plugin_explorer_plugin_description();
9999
}
100100

101101
public void OnCultureInfoChanged(CultureInfo newCulture)

Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingDownloadHelper.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public static async Task<string> PromptDownloadIfNotInstallAsync(string installe
2121
if (string.IsNullOrEmpty(installedLocation))
2222
{
2323
if (api.ShowMsgBox(
24-
string.Format(api.GetTranslation("flowlauncher_plugin_everything_installing_select"), Environment.NewLine),
25-
api.GetTranslation("flowlauncher_plugin_everything_installing_title"),
26-
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
24+
Localize.flowlauncher_plugin_everything_installing_select(Environment.NewLine),
25+
Localize.flowlauncher_plugin_everything_installing_title(),
26+
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
2727
{
2828
var dlg = new System.Windows.Forms.OpenFileDialog
2929
{
@@ -41,13 +41,13 @@ public static async Task<string> PromptDownloadIfNotInstallAsync(string installe
4141
return installedLocation;
4242
}
4343

44-
api.ShowMsg(api.GetTranslation("flowlauncher_plugin_everything_installing_title"),
45-
api.GetTranslation("flowlauncher_plugin_everything_installing_subtitle"), "", useMainWindowAsOwner: false);
44+
api.ShowMsg(Localize.flowlauncher_plugin_everything_installing_title(),
45+
Localize.flowlauncher_plugin_everything_installing_subtitle(), "", useMainWindowAsOwner: false);
4646

4747
await DroplexPackage.Drop(App.Everything1_4_1_1009).ConfigureAwait(false);
4848

49-
api.ShowMsg(api.GetTranslation("flowlauncher_plugin_everything_installing_title"),
50-
api.GetTranslation("flowlauncher_plugin_everything_installationsuccess_subtitle"), "", useMainWindowAsOwner: false);
49+
api.ShowMsg(Localize.flowlauncher_plugin_everything_installing_title(),
50+
Localize.flowlauncher_plugin_everything_installationsuccess_subtitle(), "", useMainWindowAsOwner: false);
5151

5252
installedLocation = "C:\\Program Files\\Everything\\Everything.exe";
5353

@@ -83,6 +83,5 @@ internal static string GetInstalledPath()
8383

8484
var scoopInstalledPath = Environment.ExpandEnvironmentVariables(@"%userprofile%\scoop\apps\everything\current\Everything.exe");
8585
return File.Exists(scoopInstalledPath) ? scoopInstalledPath : string.Empty;
86-
8786
}
8887
}

Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingSearchManager.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ private async ValueTask ThrowIfEverythingNotAvailableAsync(CancellationToken tok
2727
if (!await EverythingApi.IsEverythingRunningAsync(token))
2828
throw new EngineNotAvailableException(
2929
Enum.GetName(Settings.IndexSearchEngineOption.Everything)!,
30-
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_click_to_launch_or_install"),
31-
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_is_not_running"),
30+
Localize.flowlauncher_plugin_everything_click_to_launch_or_install(),
31+
Localize.flowlauncher_plugin_everything_is_not_running(),
3232
Constants.EverythingErrorImagePath,
3333
ClickToInstallEverythingAsync);
3434
}
@@ -38,7 +38,7 @@ private async ValueTask ThrowIfEverythingNotAvailableAsync(CancellationToken tok
3838
Enum.GetName(Settings.IndexSearchEngineOption.Everything)!,
3939
"Please check whether your system is x86 or x64",
4040
Constants.GeneralSearchErrorImagePath,
41-
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_sdk_issue"));
41+
Localize.flowlauncher_plugin_everything_sdk_issue());
4242
}
4343
}
4444

@@ -50,7 +50,7 @@ private async ValueTask<bool> ClickToInstallEverythingAsync(ActionContext _)
5050

5151
if (installedPath == null)
5252
{
53-
Main.Context.API.ShowMsgError(Main.Context.API.GetTranslation("flowlauncher_plugin_everything_not_found"));
53+
Main.Context.API.ShowMsgError(Localize.flowlauncher_plugin_everything_not_found());
5454
Main.Context.API.LogError(ClassName, "Unable to find Everything.exe");
5555

5656
return false;
@@ -65,7 +65,7 @@ private async ValueTask<bool> ClickToInstallEverythingAsync(ActionContext _)
6565
// Just let the user know that Everything is not installed properly and ask them to install it manually
6666
catch (Exception e)
6767
{
68-
Main.Context.API.ShowMsgError(Main.Context.API.GetTranslation("flowlauncher_plugin_everything_install_issue"));
68+
Main.Context.API.ShowMsgError(Localize.flowlauncher_plugin_everything_install_issue());
6969
Main.Context.API.LogException(ClassName, "Failed to install Everything", e);
7070

7171
return false;
@@ -97,8 +97,8 @@ public async IAsyncEnumerable<SearchResult> ContentSearchAsync(string plainSearc
9797
if (!Settings.EnableEverythingContentSearch)
9898
{
9999
throw new EngineNotAvailableException(Enum.GetName(Settings.IndexSearchEngineOption.Everything)!,
100-
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_enable_content_search"),
101-
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_enable_content_search_tips"),
100+
Localize.flowlauncher_plugin_everything_enable_content_search(),
101+
Localize.flowlauncher_plugin_everything_enable_content_search_tips(),
102102
Constants.EverythingErrorImagePath,
103103
_ =>
104104
{

Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Linq;
44
using System.Threading.Tasks;
@@ -124,7 +124,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
124124
}
125125
catch (Exception ex)
126126
{
127-
Context.API.ShowMsgBox(ex.Message, Context.API.GetTranslation("plugin_explorer_opendir_error"));
127+
Context.API.ShowMsgBox(ex.Message, Localize.plugin_explorer_opendir_error());
128128
return false;
129129
}
130130
}
@@ -138,7 +138,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
138138
}
139139
catch (Exception ex)
140140
{
141-
Context.API.ShowMsgBox(ex.Message, Context.API.GetTranslation("plugin_explorer_opendir_error"));
141+
Context.API.ShowMsgBox(ex.Message, Localize.plugin_explorer_opendir_error());
142142
return false;
143143
}
144144
}
@@ -153,7 +153,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
153153
}
154154
catch (Exception ex)
155155
{
156-
Context.API.ShowMsgBox(ex.Message, Context.API.GetTranslation("plugin_explorer_opendir_error"));
156+
Context.API.ShowMsgBox(ex.Message, Localize.plugin_explorer_opendir_error());
157157
return false;
158158
}
159159
}
@@ -166,7 +166,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
166166
return false;
167167
},
168168
Score = score,
169-
TitleToolTip = Main.Context.API.GetTranslation("plugin_explorer_plugin_ToolTipOpenDirectory"),
169+
TitleToolTip = Localize.plugin_explorer_plugin_ToolTipOpenDirectory(),
170170
SubTitleToolTip = Settings.DisplayMoreInformationInToolTip ? GetFolderMoreInfoTooltip(path) : path,
171171
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path, WindowsIndexed = windowsIndexed }
172172
};
@@ -190,7 +190,7 @@ private static Result CreateDriveSpaceDisplayResult(string path, string actionKe
190190
DriveInfo drv = new DriveInfo(driveLetter);
191191
var freespace = ToReadableSize(drv.AvailableFreeSpace, 2);
192192
var totalspace = ToReadableSize(drv.TotalSize, 2);
193-
var subtitle = string.Format(Context.API.GetTranslation("plugin_explorer_diskfreespace"), freespace, totalspace);
193+
var subtitle = Localize.plugin_explorer_diskfreespace(freespace, totalspace);
194194
double usingSize = (Convert.ToDouble(drv.TotalSize) - Convert.ToDouble(drv.AvailableFreeSpace)) / Convert.ToDouble(drv.TotalSize) * 100;
195195

196196
int? progressValue = Convert.ToInt32(usingSize);
@@ -262,8 +262,8 @@ internal static Result CreateOpenCurrentFolderResult(string path, string actionK
262262

263263
return new Result
264264
{
265-
Title = Context.API.GetTranslation("plugin_explorer_openresultfolder"),
266-
SubTitle = Context.API.GetTranslation("plugin_explorer_openresultfolder_subtitle"),
265+
Title = Localize.plugin_explorer_openresultfolder(),
266+
SubTitle = Localize.plugin_explorer_openresultfolder_subtitle(),
267267
AutoCompleteText = GetPathWithActionKeyword(folderPath, ResultType.Folder, actionKeyword),
268268
IcoPath = folderPath,
269269
Score = 500,
@@ -330,12 +330,12 @@ internal static Result CreateFileResult(string filePath, Query query, int score
330330
}
331331
catch (Exception ex)
332332
{
333-
Context.API.ShowMsgBox(ex.Message, Context.API.GetTranslation("plugin_explorer_openfile_error"));
333+
Context.API.ShowMsgBox(ex.Message, Localize.plugin_explorer_openfile_error());
334334
}
335335

336336
return true;
337337
},
338-
TitleToolTip = Main.Context.API.GetTranslation("plugin_explorer_plugin_ToolTipOpenContainingFolder"),
338+
TitleToolTip = Localize.plugin_explorer_plugin_ToolTipOpenContainingFolder(),
339339
SubTitleToolTip = Settings.DisplayMoreInformationInToolTip ? GetFileMoreInfoTooltip(filePath) : filePath,
340340
ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath, WindowsIndexed = windowsIndexed }
341341
};
@@ -374,8 +374,7 @@ private static string GetFileMoreInfoTooltip(string filePath)
374374
var fileSize = PreviewPanel.GetFileSize(filePath);
375375
var fileCreatedAt = PreviewPanel.GetFileCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
376376
var fileModifiedAt = PreviewPanel.GetFileLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
377-
return string.Format(Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info"),
378-
filePath, fileSize, fileCreatedAt, fileModifiedAt, Environment.NewLine);
377+
return Localize.plugin_explorer_plugin_tooltip_more_info(filePath, fileSize, fileCreatedAt, fileModifiedAt, Environment.NewLine);
379378
}
380379
catch (Exception e)
381380
{
@@ -391,8 +390,7 @@ private static string GetFolderMoreInfoTooltip(string folderPath)
391390
var folderSize = PreviewPanel.GetFolderSize(folderPath);
392391
var folderCreatedAt = PreviewPanel.GetFolderCreatedAt(folderPath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
393392
var folderModifiedAt = PreviewPanel.GetFolderLastModifiedAt(folderPath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
394-
return string.Format(Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info"),
395-
folderPath, folderSize, folderCreatedAt, folderModifiedAt, Environment.NewLine);
393+
return Localize.plugin_explorer_plugin_tooltip_more_info(folderPath, folderSize, folderCreatedAt, folderModifiedAt, Environment.NewLine);
396394
}
397395
catch (Exception e)
398396
{
@@ -403,8 +401,7 @@ private static string GetFolderMoreInfoTooltip(string folderPath)
403401

404402
private static string GetVolumeMoreInfoTooltip(string volumePath, string freespace, string totalspace)
405403
{
406-
return string.Format(Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_volume"),
407-
volumePath, freespace, totalspace, Environment.NewLine);
404+
return Localize.plugin_explorer_plugin_tooltip_more_info_volume(volumePath, freespace, totalspace, Environment.NewLine);
408405
}
409406

410407
private static readonly string[] MediaExtensions =

Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ private List<Result> EverythingContentSearchResult(Query query)
161161
{
162162
new()
163163
{
164-
Title = Context.API.GetTranslation("flowlauncher_plugin_everything_enable_content_search"),
165-
SubTitle = Context.API.GetTranslation("flowlauncher_plugin_everything_enable_content_search_tips"),
164+
Title = Localize.flowlauncher_plugin_everything_enable_content_search(),
165+
SubTitle = Localize.flowlauncher_plugin_everything_enable_content_search_tips(),
166166
IcoPath = "Images/index_error.png",
167167
Action = c =>
168168
{

0 commit comments

Comments
 (0)