Skip to content

Commit 41200b8

Browse files
committed
Use Flow.Launcher.Localization to improve code quality
1 parent a9364cb commit 41200b8

File tree

5 files changed

+46
-28
lines changed

5 files changed

+46
-28
lines changed

Plugins/Flow.Launcher.Plugin.Sys/CommandKeywordSetting.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public CommandKeywordSettingWindow(Command old)
1111
_oldSearchSource = old;
1212
InitializeComponent();
1313
CommandKeyword.Text = old.Keyword;
14-
CommandKeywordTips.Text = string.Format(Main.Context.API.GetTranslation("flowlauncher_plugin_sys_custom_command_keyword_tip"), old.Name);
14+
CommandKeywordTips.Text = Localize.flowlauncher_plugin_sys_custom_command_keyword_tip(old.Name);
1515
}
1616

1717
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
@@ -24,7 +24,7 @@ private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
2424
var keyword = CommandKeyword.Text;
2525
if (string.IsNullOrEmpty(keyword))
2626
{
27-
var warning = Main.Context.API.GetTranslation("flowlauncher_plugin_sys_input_command_keyword");
27+
var warning = Localize.flowlauncher_plugin_sys_input_command_keyword();
2828
Main.Context.API.ShowMsgBox(warning);
2929
}
3030
else

Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.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="Microsoft.Windows.CsWin32" Version="0.3.205">
6264
<PrivateAssets>all</PrivateAssets>
6365
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@
7878
<system:String x:Key="flowlauncher_plugin_sys_plugin_name">System Commands</system:String>
7979
<system:String x:Key="flowlauncher_plugin_sys_plugin_description">Provides System related commands. e.g. shutdown, lock, settings etc.</system:String>
8080

81+
<!-- Theme Selector -->
82+
<system:String x:Key="flowlauncher_plugin_sys_type_isdark_hasblur">This theme supports two (light/dark) modes and Blur Transparent Background</system:String>
83+
<system:String x:Key="flowlauncher_plugin_sys_type_isdark">This theme supports two (light/dark) modes</system:String>
84+
<system:String x:Key="flowlauncher_plugin_sys_type_hasblur">This theme supports Blur Transparent Background</system:String>
85+
8186
</ResourceDictionary>

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Globalization;
55
using System.Linq;
66
using System.Runtime.InteropServices;
7+
using System.Threading.Tasks;
78
using System.Windows;
89
using Windows.Win32;
910
using Windows.Win32.Foundation;
@@ -206,8 +207,8 @@ private static List<Result> Commands(Query query)
206207
Action = c =>
207208
{
208209
var result = Context.API.ShowMsgBox(
209-
Context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_shutdown_computer"),
210-
Context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"),
210+
Localize.flowlauncher_plugin_sys_dlgtext_shutdown_computer(),
211+
Localize.flowlauncher_plugin_sys_shutdown_computer(),
211212
MessageBoxButton.YesNo, MessageBoxImage.Warning);
212213

213214
if (result == MessageBoxResult.Yes)
@@ -227,8 +228,8 @@ private static List<Result> Commands(Query query)
227228
Action = c =>
228229
{
229230
var result = Context.API.ShowMsgBox(
230-
Context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer"),
231-
Context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
231+
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer(),
232+
Localize.flowlauncher_plugin_sys_restart_computer(),
232233
MessageBoxButton.YesNo, MessageBoxImage.Warning);
233234

234235
if (result == MessageBoxResult.Yes)
@@ -248,8 +249,8 @@ private static List<Result> Commands(Query query)
248249
Action = c =>
249250
{
250251
var result = Context.API.ShowMsgBox(
251-
Context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer_advanced"),
252-
Context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
252+
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer_advanced(),
253+
Localize.flowlauncher_plugin_sys_restart_computer(),
253254
MessageBoxButton.YesNo, MessageBoxImage.Warning);
254255

255256
if (result == MessageBoxResult.Yes)
@@ -269,8 +270,8 @@ private static List<Result> Commands(Query query)
269270
Action = c =>
270271
{
271272
var result = Context.API.ShowMsgBox(
272-
Context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_logoff_computer"),
273-
Context.API.GetTranslation("flowlauncher_plugin_sys_log_off"),
273+
Localize.flowlauncher_plugin_sys_dlgtext_logoff_computer(),
274+
Localize.flowlauncher_plugin_sys_log_off(),
274275
MessageBoxButton.YesNo, MessageBoxImage.Warning);
275276

276277
if (result == MessageBoxResult.Yes)
@@ -337,8 +338,8 @@ private static List<Result> Commands(Query query)
337338
if (result != HRESULT.S_OK && result != HRESULT.E_UNEXPECTED)
338339
{
339340
Context.API.ShowMsgBox(
340-
string.Format(Context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_empty_recycle_bin_failed"), Environment.NewLine),
341-
Context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_error"),
341+
Localize.flowlauncher_plugin_sys_dlgtext_empty_recycle_bin_failed(Environment.NewLine),
342+
Localize.flowlauncher_plugin_sys_dlgtitle_error(),
342343
MessageBoxButton.OK, MessageBoxImage.Error);
343344
}
344345

@@ -377,8 +378,8 @@ private static List<Result> Commands(Query query)
377378
Action = c =>
378379
{
379380
Context.API.SaveAppAllSettings();
380-
Context.API.ShowMsg(Context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
381-
Context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_all_settings_saved"));
381+
Context.API.ShowMsg(Localize.flowlauncher_plugin_sys_dlgtitle_success(),
382+
Localize.flowlauncher_plugin_sys_dlgtext_all_settings_saved());
382383
return true;
383384
}
384385
},
@@ -418,10 +419,9 @@ private static List<Result> Commands(Query query)
418419

419420
_ = Context.API.ReloadAllPluginData().ContinueWith(_ =>
420421
Context.API.ShowMsg(
421-
Context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
422-
Context.API.GetTranslation(
423-
"flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded")),
424-
System.Threading.Tasks.TaskScheduler.Current);
422+
Localize.flowlauncher_plugin_sys_dlgtitle_success(),
423+
Localize.flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded()),
424+
TaskScheduler.Current);
425425

426426
return true;
427427
}
@@ -514,12 +514,12 @@ private static List<Result> Commands(Query query)
514514

515515
public string GetTranslatedPluginTitle()
516516
{
517-
return Context.API.GetTranslation("flowlauncher_plugin_sys_plugin_name");
517+
return Localize.flowlauncher_plugin_sys_plugin_name();
518518
}
519519

520520
public string GetTranslatedPluginDescription()
521521
{
522-
return Context.API.GetTranslation("flowlauncher_plugin_sys_plugin_description");
522+
return Localize.flowlauncher_plugin_sys_plugin_description();
523523
}
524524

525525
public void OnCultureInfoChanged(CultureInfo _)

Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,28 @@ private static Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme
4343
score = 1000;
4444
}
4545

46-
string description = string.Empty;
47-
if (theme.IsDark == true)
46+
string description;
47+
if (theme.IsDark == true && theme.HasBlur == true)
4848
{
49-
description += Main.Context.API.GetTranslation("TypeIsDarkToolTip");
49+
if (theme.HasBlur == true)
50+
{
51+
description = Localize.flowlauncher_plugin_sys_type_isdark_hasblur();
52+
}
53+
else
54+
{
55+
description = Localize.flowlauncher_plugin_sys_type_isdark();
56+
}
5057
}
51-
52-
if (theme.HasBlur == true)
58+
else
5359
{
54-
if (!string.IsNullOrEmpty(description))
55-
description += " ";
56-
description += Main.Context.API.GetTranslation("TypeHasBlurToolTip");
60+
if (theme.HasBlur == true)
61+
{
62+
description = Localize.flowlauncher_plugin_sys_type_hasblur();
63+
}
64+
else
65+
{
66+
description = string.Empty;
67+
}
5768
}
5869

5970
return new Result

0 commit comments

Comments
 (0)