Skip to content

Commit 4400734

Browse files
committed
Remove InternationalizationManager.Instance
1 parent 2e740b1 commit 4400734

13 files changed

+65
-94
lines changed

Flow.Launcher.Core/Resource/InternationalizationManager.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

Flow.Launcher/ActionKeywords.xaml.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
using System.Windows;
2-
using Flow.Launcher.Core.Resource;
32
using Flow.Launcher.Plugin;
43
using Flow.Launcher.ViewModel;
5-
using Flow.Launcher.Core;
64
using System.Linq;
75
using System.Collections.Generic;
86

97
namespace Flow.Launcher
108
{
119
public partial class ActionKeywords
1210
{
13-
private readonly PluginPair plugin;
14-
private readonly Internationalization translater = InternationalizationManager.Instance;
15-
private readonly PluginViewModel pluginViewModel;
11+
private readonly PluginPair _plugin;
12+
private readonly PluginViewModel _pluginViewModel;
1613

1714
public ActionKeywords(PluginViewModel pluginViewModel)
1815
{
1916
InitializeComponent();
20-
plugin = pluginViewModel.PluginPair;
21-
this.pluginViewModel = pluginViewModel;
17+
_plugin = pluginViewModel.PluginPair;
18+
_pluginViewModel = pluginViewModel;
2219
}
2320

2421
private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e)
2522
{
26-
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeparator, plugin.Metadata.ActionKeywords.ToArray());
23+
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeparator, _plugin.Metadata.ActionKeywords.ToArray());
2724
tbAction.Focus();
2825
}
2926

@@ -34,7 +31,7 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
3431

3532
private void btnDone_OnClick(object sender, RoutedEventArgs _)
3633
{
37-
var oldActionKeywords = plugin.Metadata.ActionKeywords;
34+
var oldActionKeywords = _plugin.Metadata.ActionKeywords;
3835

3936
var newActionKeywords = tbAction.Text.Split(Query.ActionKeywordSeparator).ToList();
4037
newActionKeywords.RemoveAll(string.IsNullOrEmpty);
@@ -48,7 +45,7 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
4845
{
4946
if (oldActionKeywords.Count != newActionKeywords.Count)
5047
{
51-
ReplaceActionKeyword(plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
48+
ReplaceActionKeyword(_plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
5249
return;
5350
}
5451

@@ -58,18 +55,16 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
5855
if (sortedOldActionKeywords.SequenceEqual(sortedNewActionKeywords))
5956
{
6057
// User just changes the sequence of action keywords
61-
var msg = translater.GetTranslation("newActionKeywordsSameAsOld");
62-
MessageBoxEx.Show(msg);
58+
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsSameAsOld"));
6359
}
6460
else
6561
{
66-
ReplaceActionKeyword(plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
62+
ReplaceActionKeyword(_plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
6763
}
6864
}
6965
else
7066
{
71-
string msg = translater.GetTranslation("newActionKeywordsHasBeenAssigned");
72-
App.API.ShowMsgBox(msg);
67+
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsHasBeenAssigned"));
7368
}
7469
}
7570

@@ -85,7 +80,7 @@ private void ReplaceActionKeyword(string id, IReadOnlyList<string> removedAction
8580
}
8681

8782
// Update action keywords text and close window
88-
pluginViewModel.OnActionKeywordsChanged();
83+
_pluginViewModel.OnActionKeywordsChanged();
8984
Close();
9085
}
9186
}

Flow.Launcher/Converters/TextConverter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Globalization;
33
using System.Windows.Data;
4-
using Flow.Launcher.Core.Resource;
54
using Flow.Launcher.ViewModel;
65

76
namespace Flow.Launcher.Converters;
@@ -23,7 +22,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
2322
if (translationKey is null)
2423
return id;
2524

26-
return InternationalizationManager.Instance.GetTranslation(translationKey);
25+
return App.API.GetTranslation(translationKey);
2726
}
2827

2928
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new InvalidOperationException();

Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Flow.Launcher.Core.Resource;
2-
using Flow.Launcher.Helper;
1+
using Flow.Launcher.Helper;
32
using Flow.Launcher.Infrastructure.UserSettings;
43
using System.Collections.ObjectModel;
54
using System.Linq;
@@ -53,22 +52,21 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
5352
Close();
5453
}
5554

56-
5755
public void UpdateItem(CustomPluginHotkey item)
5856
{
5957
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
6058
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
6159
if (updateCustomHotkey == null)
6260
{
63-
App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("invalidPluginHotkey"));
61+
App.API.ShowMsgBox(App.API.GetTranslation("invalidPluginHotkey"));
6462
Close();
6563
return;
6664
}
6765

6866
tbAction.Text = updateCustomHotkey.ActionKeyword;
6967
HotkeyControl.SetHotkey(updateCustomHotkey.Hotkey, false);
7068
update = true;
71-
lblAdd.Text = InternationalizationManager.Instance.GetTranslation("update");
69+
lblAdd.Text = App.API.GetTranslation("update");
7270
}
7371

7472
private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)

Flow.Launcher/CustomShortcutSetting.xaml.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
using Flow.Launcher.Core.Resource;
2-
using System;
1+
using System;
32
using System.Windows;
43
using System.Windows.Input;
54
using Flow.Launcher.SettingPages.ViewModels;
6-
using Flow.Launcher.Core;
75

86
namespace Flow.Launcher
97
{
@@ -41,15 +39,15 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
4139

4240
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
4341
{
44-
if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value))
42+
if (string.IsNullOrEmpty(Key) || string.IsNullOrEmpty(Value))
4543
{
46-
App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("emptyShortcut"));
44+
App.API.ShowMsgBox(App.API.GetTranslation("emptyShortcut"));
4745
return;
4846
}
4947
// Check if key is modified or adding a new one
5048
if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key))
5149
{
52-
App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("duplicateShortcut"));
50+
App.API.ShowMsgBox(App.API.GetTranslation("duplicateShortcut"));
5351
return;
5452
}
5553
DialogResult = !update || originalKey != Key || originalValue != Value;

Flow.Launcher/Helper/HotKeyMapper.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System;
44
using NHotkey;
55
using NHotkey.Wpf;
6-
using Flow.Launcher.Core.Resource;
76
using Flow.Launcher.ViewModel;
87
using ChefKeys;
98
using Flow.Launcher.Infrastructure.Logger;
@@ -56,8 +55,8 @@ private static void SetWithChefKeys(string hotkeyStr)
5655
string.Format("|HotkeyMapper.SetWithChefKeys|Error registering hotkey: {0} \nStackTrace:{1}",
5756
e.Message,
5857
e.StackTrace));
59-
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
60-
string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle");
58+
string errorMsg = string.Format(App.API.GetTranslation("registerHotkeyFailed"), hotkeyStr);
59+
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
6160
MessageBoxEx.Show(errorMsg, errorMsgTitle);
6261
}
6362
}
@@ -82,8 +81,8 @@ internal static void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs>
8281
e.Message,
8382
e.StackTrace,
8483
hotkeyStr));
85-
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
86-
string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle");
84+
string errorMsg = string.Format(App.API.GetTranslation("registerHotkeyFailed"), hotkeyStr);
85+
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
8786
App.API.ShowMsgBox(errorMsg, errorMsgTitle);
8887
}
8988
}
@@ -107,8 +106,8 @@ internal static void RemoveHotkey(string hotkeyStr)
107106
string.Format("|HotkeyMapper.RemoveHotkey|Error removing hotkey: {0} \nStackTrace:{1}",
108107
e.Message,
109108
e.StackTrace));
110-
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("unregisterHotkeyFailed"), hotkeyStr);
111-
string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle");
109+
string errorMsg = string.Format(App.API.GetTranslation("unregisterHotkeyFailed"), hotkeyStr);
110+
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
112111
MessageBoxEx.Show(errorMsg, errorMsgTitle);
113112
}
114113
}

Flow.Launcher/HotkeyControl.xaml.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Windows;
66
using System.Windows.Input;
77
using CommunityToolkit.Mvvm.DependencyInjection;
8-
using Flow.Launcher.Core.Resource;
98
using Flow.Launcher.Helper;
109
using Flow.Launcher.Infrastructure.Hotkey;
1110
using Flow.Launcher.Infrastructure.UserSettings;
@@ -65,7 +64,6 @@ private static void OnHotkeyChanged(DependencyObject d, DependencyPropertyChange
6564
hotkeyControl.RefreshHotkeyInterface(hotkeyControl.Hotkey);
6665
}
6766

68-
6967
public static readonly DependencyProperty ChangeHotkeyProperty = DependencyProperty.Register(
7068
nameof(ChangeHotkey),
7169
typeof(ICommand),
@@ -79,7 +77,6 @@ public ICommand? ChangeHotkey
7977
set { SetValue(ChangeHotkeyProperty, value); }
8078
}
8179

82-
8380
public static readonly DependencyProperty TypeProperty = DependencyProperty.Register(
8481
nameof(Type),
8582
typeof(HotkeyType),
@@ -227,19 +224,18 @@ private void RefreshHotkeyInterface(string hotkey)
227224
private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) =>
228225
hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey);
229226

230-
public string EmptyHotkey => InternationalizationManager.Instance.GetTranslation("none");
227+
public string EmptyHotkey => App.API.GetTranslation("none");
231228

232229
public ObservableCollection<string> KeysToDisplay { get; set; } = new();
233230

234231
public HotkeyModel CurrentHotkey { get; private set; } = new(false, false, false, false, Key.None);
235232

236-
237233
public void GetNewHotkey(object sender, RoutedEventArgs e)
238234
{
239-
OpenHotkeyDialog();
235+
_ = OpenHotkeyDialogAsync();
240236
}
241237

242-
private async Task OpenHotkeyDialog()
238+
private async Task OpenHotkeyDialogAsync()
243239
{
244240
if (!string.IsNullOrEmpty(Hotkey))
245241
{
@@ -262,12 +258,11 @@ private async Task OpenHotkeyDialog()
262258
}
263259
}
264260

265-
266261
private void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true)
267262
{
268263
if (triggerValidate)
269264
{
270-
bool hotkeyAvailable = false;
265+
bool hotkeyAvailable;
271266
// TODO: This is a temporary way to enforce changing only the open flow hotkey to Win, and will be removed by PR #3157
272267
if (keyModel.ToString() == "LWin" || keyModel.ToString() == "RWin")
273268
{

Flow.Launcher/HotkeyControlDialog.xaml.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Windows.Input;
66
using ChefKeys;
77
using CommunityToolkit.Mvvm.DependencyInjection;
8-
using Flow.Launcher.Core.Resource;
98
using Flow.Launcher.Helper;
109
using Flow.Launcher.Infrastructure.Hotkey;
1110
using Flow.Launcher.Infrastructure.UserSettings;
@@ -34,15 +33,15 @@ public enum EResultType
3433

3534
public EResultType ResultType { get; private set; } = EResultType.Cancel;
3635
public string ResultValue { get; private set; } = string.Empty;
37-
public static string EmptyHotkey => InternationalizationManager.Instance.GetTranslation("none");
36+
public static string EmptyHotkey => App.API.GetTranslation("none");
3837

3938
private static bool isOpenFlowHotkey;
4039

4140
public HotkeyControlDialog(string hotkey, string defaultHotkey, string windowTitle = "")
4241
{
4342
WindowTitle = windowTitle switch
4443
{
45-
"" or null => InternationalizationManager.Instance.GetTranslation("hotkeyRegTitle"),
44+
"" or null => App.API.GetTranslation("hotkeyRegTitle"),
4645
_ => windowTitle
4746
};
4847
DefaultHotkey = defaultHotkey;
@@ -141,14 +140,14 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)
141140
if (_hotkeySettings.RegisteredHotkeys.FirstOrDefault(v => v.Hotkey == hotkey) is { } registeredHotkeyData)
142141
{
143142
var description = string.Format(
144-
InternationalizationManager.Instance.GetTranslation(registeredHotkeyData.DescriptionResourceKey),
143+
App.API.GetTranslation(registeredHotkeyData.DescriptionResourceKey),
145144
registeredHotkeyData.DescriptionFormatVariables
146145
);
147146
Alert.Visibility = Visibility.Visible;
148147
if (registeredHotkeyData.RemoveHotkey is not null)
149148
{
150149
tbMsg.Text = string.Format(
151-
InternationalizationManager.Instance.GetTranslation("hotkeyUnavailableEditable"),
150+
App.API.GetTranslation("hotkeyUnavailableEditable"),
152151
description
153152
);
154153
SaveBtn.IsEnabled = false;
@@ -160,7 +159,7 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)
160159
else
161160
{
162161
tbMsg.Text = string.Format(
163-
InternationalizationManager.Instance.GetTranslation("hotkeyUnavailableUneditable"),
162+
App.API.GetTranslation("hotkeyUnavailableUneditable"),
164163
description
165164
);
166165
SaveBtn.IsEnabled = false;
@@ -176,7 +175,7 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)
176175

177176
if (!CheckHotkeyAvailability(hotkey.Value, true))
178177
{
179-
tbMsg.Text = InternationalizationManager.Instance.GetTranslation("hotkeyUnavailable");
178+
tbMsg.Text = App.API.GetTranslation("hotkeyUnavailable");
180179
Alert.Visibility = Visibility.Visible;
181180
SaveBtn.IsEnabled = false;
182181
SaveBtn.Visibility = Visibility.Visible;

Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
1717
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 1;
1818
InitializeComponent();
1919
}
20-
private Internationalization _translater => InternationalizationManager.Instance;
20+
21+
private readonly Internationalization _translater = Ioc.Default.GetRequiredService<Internationalization>();
22+
2123
public List<Language> Languages => _translater.LoadAvailableLanguages();
2224

2325
public Settings Settings { get; set; }
@@ -30,12 +32,11 @@ public string CustomLanguage
3032
}
3133
set
3234
{
33-
InternationalizationManager.Instance.ChangeLanguage(value);
35+
_translater.ChangeLanguage(value);
3436

35-
if (InternationalizationManager.Instance.PromptShouldUsePinyin(value))
37+
if (_translater.PromptShouldUsePinyin(value))
3638
Settings.ShouldUsePinyin = true;
3739
}
3840
}
39-
4041
}
4142
}

0 commit comments

Comments
 (0)