Skip to content

Commit d87650d

Browse files
committed
Use Flow.Launcher.Localization to improve code quality
1 parent 4865224 commit d87650d

25 files changed

+134
-143
lines changed

Flow.Launcher/ActionKeywords.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
4747

4848
if (addedActionKeywords.Any(App.API.ActionKeywordAssigned))
4949
{
50-
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsHasBeenAssigned"));
50+
App.API.ShowMsgBox(Localize.newActionKeywordsHasBeenAssigned());
5151
return;
5252
}
5353

@@ -63,7 +63,7 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
6363
if (sortedOldActionKeywords.SequenceEqual(sortedNewActionKeywords))
6464
{
6565
// User just changes the sequence of action keywords
66-
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsSameAsOld"));
66+
App.API.ShowMsgBox(Localize.newActionKeywordsSameAsOld());
6767
}
6868
else
6969
{

Flow.Launcher/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ private static void AutoStartup()
276276
// but if it fails (permissions, etc) then don't keep retrying
277277
// this also gives the user a visual indication in the Settings widget
278278
_settings.StartFlowLauncherOnSystemStartup = false;
279-
API.ShowMsgError(API.GetTranslation("setAutoStartFailed"), e.Message);
279+
API.ShowMsgError(Localize.setAutoStartFailed(), e.Message);
280280
}
281281
}
282282
}

Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
4141

4242
if (string.IsNullOrEmpty(Hotkey) && string.IsNullOrEmpty(ActionKeyword))
4343
{
44-
App.API.ShowMsgBox(App.API.GetTranslation("emptyPluginHotkey"));
44+
App.API.ShowMsgBox(Localize.emptyPluginHotkey());
4545
return;
4646
}
4747

Flow.Launcher/CustomShortcutSetting.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
4040
{
4141
if (string.IsNullOrEmpty(Key) || string.IsNullOrEmpty(Value))
4242
{
43-
App.API.ShowMsgBox(App.API.GetTranslation("emptyShortcut"));
43+
App.API.ShowMsgBox(Localize.emptyShortcut());
4444
return;
4545
}
4646

4747
// Check if key is modified or adding a new one
4848
if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key))
4949
{
50-
App.API.ShowMsgBox(App.API.GetTranslation("duplicateShortcut"));
50+
App.API.ShowMsgBox(Localize.duplicateShortcut());
5151
return;
5252
}
5353

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<ErrorReport>prompt</ErrorReport>
3838
<WarningLevel>4</WarningLevel>
3939
<Prefer32Bit>false</Prefer32Bit>
40+
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
4041
</PropertyGroup>
4142

4243
<Target Name="RemoveUnnecessaryRuntimesAfterBuild" AfterTargets="Build">
@@ -132,6 +133,7 @@
132133
<ItemGroup>
133134
<PackageReference Include="ChefKeys" Version="0.1.2" />
134135
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
136+
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
135137
<PackageReference Include="Fody" Version="6.9.3">
136138
<PrivateAssets>all</PrivateAssets>
137139
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -161,6 +163,10 @@
161163
<ProjectReference Include="..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
162164
</ItemGroup>
163165

166+
<PropertyGroup>
167+
<FLLUseDependencyInjection>true</FLLUseDependencyInjection>
168+
</PropertyGroup>
169+
164170
<ItemGroup>
165171
<Content Include="Resources\open.wav">
166172
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

Flow.Launcher/Helper/HotKeyMapper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ private static void SetWithChefKeys(string hotkeyStr)
6161
string.Format("|HotkeyMapper.SetWithChefKeys|Error registering hotkey: {0} \nStackTrace:{1}",
6262
e.Message,
6363
e.StackTrace));
64-
string errorMsg = string.Format(App.API.GetTranslation("registerHotkeyFailed"), hotkeyStr);
65-
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
64+
string errorMsg = Localize.registerHotkeyFailed(hotkeyStr);
65+
string errorMsgTitle = Localize.MessageBoxTitle();
6666
App.API.ShowMsgBox(errorMsg, errorMsgTitle);
6767
}
6868
}
@@ -87,8 +87,8 @@ internal static void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs>
8787
e.Message,
8888
e.StackTrace,
8989
hotkeyStr));
90-
string errorMsg = string.Format(App.API.GetTranslation("registerHotkeyFailed"), hotkeyStr);
91-
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
90+
string errorMsg = Localize.registerHotkeyFailed(hotkeyStr);
91+
string errorMsgTitle = Localize.MessageBoxTitle();
9292
App.API.ShowMsgBox(errorMsg, errorMsgTitle);
9393
}
9494
}
@@ -112,8 +112,8 @@ internal static void RemoveHotkey(string hotkeyStr)
112112
string.Format("|HotkeyMapper.RemoveHotkey|Error removing hotkey: {0} \nStackTrace:{1}",
113113
e.Message,
114114
e.StackTrace));
115-
string errorMsg = string.Format(App.API.GetTranslation("unregisterHotkeyFailed"), hotkeyStr);
116-
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
115+
string errorMsg = Localize.unregisterHotkeyFailed(hotkeyStr);
116+
string errorMsgTitle = Localize.MessageBoxTitle();
117117
App.API.ShowMsgBox(errorMsg, errorMsgTitle);
118118
}
119119
}

Flow.Launcher/HotkeyControl.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
22
using System.Threading.Tasks;
33
using System.Windows;
44
using System.Windows.Input;
@@ -234,7 +234,7 @@ private void RefreshHotkeyInterface(string hotkey)
234234
private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) =>
235235
hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey);
236236

237-
public string EmptyHotkey => App.API.GetTranslation("none");
237+
public string EmptyHotkey => Localize.none();
238238

239239
public ObservableCollection<string> KeysToDisplay { get; set; } = new();
240240

Flow.Launcher/HotkeyControlDialog.xaml.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public enum EResultType
3333

3434
public EResultType ResultType { get; private set; } = EResultType.Cancel;
3535
public string ResultValue { get; private set; } = string.Empty;
36-
public static string EmptyHotkey => App.API.GetTranslation("none");
36+
public static string EmptyHotkey => Localize.none();
3737

3838
private static bool isOpenFlowHotkey;
3939

4040
public HotkeyControlDialog(string hotkey, string defaultHotkey, string windowTitle = "")
4141
{
4242
WindowTitle = windowTitle switch
4343
{
44-
"" or null => App.API.GetTranslation("hotkeyRegTitle"),
44+
"" or null => Localize.hotkeyRegTitle(),
4545
_ => windowTitle
4646
};
4747
DefaultHotkey = defaultHotkey;
@@ -146,10 +146,7 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)
146146
Alert.Visibility = Visibility.Visible;
147147
if (registeredHotkeyData.RemoveHotkey is not null)
148148
{
149-
tbMsg.Text = string.Format(
150-
App.API.GetTranslation("hotkeyUnavailableEditable"),
151-
description
152-
);
149+
tbMsg.Text = Localize.hotkeyUnavailableEditable(description);
153150
SaveBtn.IsEnabled = false;
154151
SaveBtn.Visibility = Visibility.Collapsed;
155152
OverwriteBtn.IsEnabled = true;
@@ -158,10 +155,7 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)
158155
}
159156
else
160157
{
161-
tbMsg.Text = string.Format(
162-
App.API.GetTranslation("hotkeyUnavailableUneditable"),
163-
description
164-
);
158+
tbMsg.Text = Localize.hotkeyUnavailableUneditable(description);
165159
SaveBtn.IsEnabled = false;
166160
SaveBtn.Visibility = Visibility.Visible;
167161
OverwriteBtn.IsEnabled = false;
@@ -175,7 +169,7 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)
175169

176170
if (!CheckHotkeyAvailability(hotkey.Value, true))
177171
{
178-
tbMsg.Text = App.API.GetTranslation("hotkeyUnavailable");
172+
tbMsg.Text = Localize.hotkeyUnavailable();
179173
Alert.Visibility = Visibility.Visible;
180174
SaveBtn.IsEnabled = false;
181175
SaveBtn.Visibility = Visibility.Visible;

Flow.Launcher/Languages/en.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@
209209
<system:String x:Key="plugin_query_version">Version</system:String>
210210
<system:String x:Key="plugin_query_web">Website</system:String>
211211
<system:String x:Key="plugin_uninstall">Uninstall</system:String>
212+
<system:String x:Key="plugin_default_search_delay_time">Search delay time: default</system:String>
213+
<system:String x:Key="plugin_search_delay_time">Search delay time: {0}ms</system:String>
212214
<system:String x:Key="failedToRemovePluginSettingsTitle">Fail to remove plugin settings</system:String>
213215
<system:String x:Key="failedToRemovePluginSettingsMessage">Plugins: {0} - Fail to remove plugin settings files, please remove them manually</system:String>
214216
<system:String x:Key="failedToRemovePluginCacheTitle">Fail to remove plugin cache</system:String>
@@ -588,7 +590,7 @@
588590
The specified file manager could not be found. Please check the Custom File Manager setting under Settings > General.
589591
</system:String>
590592
<system:String x:Key="errorTitle">Error</system:String>
591-
<system:String x:Key="folderOpenError">An error occurred while opening the folder. {0}</system:String>
593+
<system:String x:Key="folderOpenError">An error occurred while opening the folder.</system:String>
592594
<system:String x:Key="browserOpenError">An error occurred while opening the URL in the browser. Please check your Default Web Browser configuration in the General section of the settings window</system:String>
593595
<system:String x:Key="fileNotFoundError">File or directory not found: {0}</system:String>
594596

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.ComponentModel;
33
using System.Linq;
44
using System.Media;
@@ -145,8 +145,8 @@ private void OnLoaded(object sender, RoutedEventArgs e)
145145
_settings.ReleaseNotesVersion = Constant.Version;
146146
// Show release note popup with button
147147
App.API.ShowMsgWithButton(
148-
string.Format(App.API.GetTranslation("appUpdateTitle"), Constant.Version),
149-
App.API.GetTranslation("appUpdateButtonContent"),
148+
Localize.appUpdateTitle(Constant.Version),
149+
Localize.appUpdateButtonContent(),
150150
() =>
151151
{
152152
Application.Current.Dispatcher.Invoke(() =>
@@ -753,12 +753,12 @@ private void InitializeNotifyIcon()
753753
private void UpdateNotifyIconText()
754754
{
755755
var menu = _contextMenu;
756-
((MenuItem)menu.Items[0]).Header = App.API.GetTranslation("iconTrayOpen") +
756+
((MenuItem)menu.Items[0]).Header = Localize.iconTrayOpen()+
757757
" (" + _settings.Hotkey + ")";
758-
((MenuItem)menu.Items[1]).Header = App.API.GetTranslation("GameMode");
759-
((MenuItem)menu.Items[2]).Header = App.API.GetTranslation("PositionReset");
760-
((MenuItem)menu.Items[3]).Header = App.API.GetTranslation("iconTraySettings");
761-
((MenuItem)menu.Items[4]).Header = App.API.GetTranslation("iconTrayExit");
758+
((MenuItem)menu.Items[1]).Header = Localize.GameMode();
759+
((MenuItem)menu.Items[2]).Header = Localize.PositionReset();
760+
((MenuItem)menu.Items[3]).Header = Localize.iconTraySettings();
761+
((MenuItem)menu.Items[4]).Header = Localize.iconTrayExit();
762762
}
763763

764764
private void InitializeContextMenu()
@@ -768,31 +768,31 @@ private void InitializeContextMenu()
768768
var openIcon = new FontIcon { Glyph = "\ue71e" };
769769
var open = new MenuItem
770770
{
771-
Header = App.API.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")",
771+
Header = Localize.iconTrayOpen()+ " (" + _settings.Hotkey + ")",
772772
Icon = openIcon
773773
};
774774
var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" };
775775
var gamemode = new MenuItem
776776
{
777-
Header = App.API.GetTranslation("GameMode"),
777+
Header = Localize.GameMode(),
778778
Icon = gamemodeIcon
779779
};
780780
var positionresetIcon = new FontIcon { Glyph = "\ue73f" };
781781
var positionreset = new MenuItem
782782
{
783-
Header = App.API.GetTranslation("PositionReset"),
783+
Header = Localize.PositionReset(),
784784
Icon = positionresetIcon
785785
};
786786
var settingsIcon = new FontIcon { Glyph = "\ue713" };
787787
var settings = new MenuItem
788788
{
789-
Header = App.API.GetTranslation("iconTraySettings"),
789+
Header = Localize.iconTraySettings(),
790790
Icon = settingsIcon
791791
};
792792
var exitIcon = new FontIcon { Glyph = "\ue7e8" };
793793
var exit = new MenuItem
794794
{
795-
Header = App.API.GetTranslation("iconTrayExit"),
795+
Header = Localize.iconTrayExit(),
796796
Icon = exitIcon
797797
};
798798

@@ -802,8 +802,8 @@ private void InitializeContextMenu()
802802
settings.Click += (o, e) => App.API.OpenSettingDialog();
803803
exit.Click += (o, e) => Close();
804804

805-
gamemode.ToolTip = App.API.GetTranslation("GameModeToolTip");
806-
positionreset.ToolTip = App.API.GetTranslation("PositionResetToolTip");
805+
gamemode.ToolTip = Localize.GameModeToolTip();
806+
positionreset.ToolTip = Localize.PositionResetToolTip();
807807

808808
_contextMenu.Items.Add(open);
809809
_contextMenu.Items.Add(gamemode);

0 commit comments

Comments
 (0)