Skip to content

Commit e286143

Browse files
committed
Use Flow.Launcher.Localization to improve code quality
1 parent 26ec51c commit e286143

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

Plugins/Flow.Launcher.Plugin.Shell/Flow.Launcher.Plugin.Shell.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<ErrorReport>prompt</ErrorReport>
3535
<WarningLevel>4</WarningLevel>
3636
<Prefer32Bit>false</Prefer32Bit>
37+
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
3738
</PropertyGroup>
3839

3940
<ItemGroup>
@@ -58,6 +59,7 @@
5859
</ItemGroup>
5960

6061
<ItemGroup>
62+
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
6163
<PackageReference Include="InputSimulator" Version="1.0.4" NoWarn="NU1701" />
6264
</ItemGroup>
6365

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu, IDispo
1717
{
1818
private static readonly string ClassName = nameof(Main);
1919

20-
internal PluginInitContext Context { get; private set; }
20+
internal static PluginInitContext Context { get; private set; }
2121

2222
private const string Image = "Images/shell.png";
2323
private bool _winRStroked;
@@ -103,14 +103,14 @@ private List<Result> GetHistoryCmds(string cmd, Result result)
103103
{
104104
if (m.Key == cmd)
105105
{
106-
result.SubTitle = string.Format(Context.API.GetTranslation("flowlauncher_plugin_cmd_cmd_has_been_executed_times"), m.Value);
106+
result.SubTitle = Localize.flowlauncher_plugin_cmd_cmd_has_been_executed_times(m.Value);
107107
return null;
108108
}
109109

110110
var ret = new Result
111111
{
112112
Title = m.Key,
113-
SubTitle = string.Format(Context.API.GetTranslation("flowlauncher_plugin_cmd_cmd_has_been_executed_times"), m.Value),
113+
SubTitle = Localize.flowlauncher_plugin_cmd_cmd_has_been_executed_times(m.Value),
114114
IcoPath = Image,
115115
Action = c =>
116116
{
@@ -140,7 +140,7 @@ private Result GetCurrentCmd(string cmd)
140140
{
141141
Title = cmd,
142142
Score = 5000,
143-
SubTitle = Context.API.GetTranslation("flowlauncher_plugin_cmd_execute_through_shell"),
143+
SubTitle = Localize.flowlauncher_plugin_cmd_execute_through_shell(),
144144
IcoPath = Image,
145145
Action = c =>
146146
{
@@ -165,7 +165,7 @@ private List<Result> ResultsFromHistory()
165165
.Select(m => new Result
166166
{
167167
Title = m.Key,
168-
SubTitle = string.Format(Context.API.GetTranslation("flowlauncher_plugin_cmd_cmd_has_been_executed_times"), m.Value),
168+
SubTitle = Localize.flowlauncher_plugin_cmd_cmd_has_been_executed_times(m.Value),
169169
IcoPath = Image,
170170
Action = c =>
171171
{
@@ -199,7 +199,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
199199
Verb = runAsAdministratorArg,
200200
WorkingDirectory = workingDirectory,
201201
};
202-
var notifyStr = Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close");
202+
var notifyStr = Localize.flowlauncher_plugin_cmd_press_any_key_to_close();
203203
var addedCharacter = _settings.UseWindowsTerminal ? "\\" : "";
204204
switch (_settings.Shell)
205205
{
@@ -336,12 +336,12 @@ private void Execute(Func<ProcessStartInfo, Process> startProcess, ProcessStartI
336336
catch (FileNotFoundException e)
337337
{
338338
Context.API.ShowMsgError(GetTranslatedPluginTitle(),
339-
string.Format(Context.API.GetTranslation("flowlauncher_plugin_cmd_command_not_found"), e.Message));
339+
Localize.flowlauncher_plugin_cmd_command_not_found(e.Message));
340340
}
341341
catch (Win32Exception e)
342342
{
343343
Context.API.ShowMsgError(GetTranslatedPluginTitle(),
344-
string.Format(Context.API.GetTranslation("flowlauncher_plugin_cmd_error_running_command"), e.Message));
344+
Localize.flowlauncher_plugin_cmd_error_running_command(e.Message));
345345
}
346346
catch (Exception e)
347347
{
@@ -405,7 +405,7 @@ bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state)
405405
return true;
406406
}
407407

408-
private void OnWinRPressed()
408+
private static void OnWinRPressed()
409409
{
410410
Context.API.ShowMainWindow();
411411
// show the main window and set focus to the query box
@@ -428,12 +428,12 @@ public Control CreateSettingPanel()
428428

429429
public string GetTranslatedPluginTitle()
430430
{
431-
return Context.API.GetTranslation("flowlauncher_plugin_cmd_plugin_name");
431+
return Localize.flowlauncher_plugin_cmd_plugin_name();
432432
}
433433

434434
public string GetTranslatedPluginDescription()
435435
{
436-
return Context.API.GetTranslation("flowlauncher_plugin_cmd_plugin_description");
436+
return Localize.flowlauncher_plugin_cmd_plugin_description();
437437
}
438438

439439
public List<Result> LoadContextMenus(Result selectedResult)
@@ -442,7 +442,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
442442
{
443443
new()
444444
{
445-
Title = Context.API.GetTranslation("flowlauncher_plugin_cmd_run_as_different_user"),
445+
Title = Localize.flowlauncher_plugin_cmd_run_as_different_user(),
446446
Action = c =>
447447
{
448448
Execute(ShellCommand.RunAsDifferentUser, PrepareProcessStartInfo(selectedResult.Title));
@@ -453,7 +453,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
453453
},
454454
new()
455455
{
456-
Title = Context.API.GetTranslation("flowlauncher_plugin_cmd_run_as_administrator"),
456+
Title = Localize.flowlauncher_plugin_cmd_run_as_administrator(),
457457
Action = c =>
458458
{
459459
Execute(Process.Start, PrepareProcessStartInfo(selectedResult.Title, true));
@@ -464,7 +464,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
464464
},
465465
new()
466466
{
467-
Title = Context.API.GetTranslation("flowlauncher_plugin_cmd_copy"),
467+
Title = Localize.flowlauncher_plugin_cmd_copy(),
468468
Action = c =>
469469
{
470470
Context.API.CopyToClipboard(selectedResult.Title);

0 commit comments

Comments
 (0)