Skip to content

Commit 8eb3b84

Browse files
committed
Remove InternationalizationManager.Instance
1 parent bbc7b53 commit 8eb3b84

28 files changed

+126
-162
lines changed

Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Linq;
88
using System.Windows;
99
using System.Windows.Forms;
10-
using Flow.Launcher.Core.Resource;
1110
using CommunityToolkit.Mvvm.DependencyInjection;
1211

1312
namespace Flow.Launcher.Core.ExternalPlugins.Environments
@@ -55,14 +54,14 @@ internal IEnumerable<PluginPair> Setup()
5554
}
5655

5756
var noRuntimeMessage = string.Format(
58-
InternationalizationManager.Instance.GetTranslation("runtimePluginInstalledChooseRuntimePrompt"),
57+
API.GetTranslation("runtimePluginInstalledChooseRuntimePrompt"),
5958
Language,
6059
EnvName,
6160
Environment.NewLine
6261
);
6362
if (API.ShowMsgBox(noRuntimeMessage, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
6463
{
65-
var msg = string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginChooseRuntimeExecutable"), EnvName);
64+
var msg = string.Format(API.GetTranslation("runtimePluginChooseRuntimeExecutable"), EnvName);
6665
string selectedFile;
6766

6867
selectedFile = GetFileFromDialog(msg, FileDialogFilter);
@@ -85,7 +84,7 @@ internal IEnumerable<PluginPair> Setup()
8584
}
8685
else
8786
{
88-
API.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language));
87+
API.ShowMsgBox(string.Format(API.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language));
8988
Log.Error("PluginsLoader",
9089
$"Not able to successfully set {EnvName} path, setting's plugin executable path variable is still an empty string.",
9190
$"{Language}Environment");

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ public static async Task InitializePluginsAsync()
203203
}
204204
}
205205

206-
InternationalizationManager.Instance.AddPluginLanguageDirectories(GetPluginsForInterface<IPluginI18n>());
207-
InternationalizationManager.Instance.ChangeLanguage(Ioc.Default.GetRequiredService<Settings>().Language);
206+
var translater = Ioc.Default.GetRequiredService<Internationalization>();
207+
translater.AddPluginLanguageDirectories(GetPluginsForInterface<IPluginI18n>());
208+
translater.ChangeLanguage(Ioc.Default.GetRequiredService<Settings>().Language);
208209

209210
if (failedPlugins.Any())
210211
{

Flow.Launcher.Core/Resource/InternationalizationManager.cs

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

Flow.Launcher.Core/Resource/LocalizedDescriptionAttribute.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
using System.ComponentModel;
2+
using CommunityToolkit.Mvvm.DependencyInjection;
3+
using Flow.Launcher.Plugin;
24

35
namespace Flow.Launcher.Core.Resource
46
{
57
public class LocalizedDescriptionAttribute : DescriptionAttribute
68
{
7-
private readonly Internationalization _translator;
9+
private static readonly IPublicAPI _api = Ioc.Default.GetRequiredService<IPublicAPI>();
810
private readonly string _resourceKey;
911

1012
public LocalizedDescriptionAttribute(string resourceKey)
1113
{
12-
_translator = InternationalizationManager.Instance;
1314
_resourceKey = resourceKey;
1415
}
1516

1617
public override string Description
1718
{
1819
get
1920
{
20-
string description = _translator.GetTranslation(_resourceKey);
21+
string description = _api.GetTranslation(_resourceKey);
2122
return string.IsNullOrWhiteSpace(description) ?
2223
string.Format("[[{0}]]", _resourceKey) : description;
2324
}

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Flow.Launcher.Infrastructure;
1313
using Flow.Launcher.Infrastructure.Logger;
1414
using Flow.Launcher.Infrastructure.UserSettings;
15-
using CommunityToolkit.Mvvm.DependencyInjection;
1615
using Flow.Launcher.Plugin;
1716

1817
namespace Flow.Launcher.Core.Resource
@@ -115,7 +114,7 @@ public bool ChangeTheme(string theme)
115114
Log.Error($"|Theme.ChangeTheme|Theme <{theme}> path can't be found");
116115
if (theme != defaultTheme)
117116
{
118-
_api.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_path_not_exists"), theme));
117+
_api.ShowMsgBox(string.Format(_api.GetTranslation("theme_load_failure_path_not_exists"), theme));
119118
ChangeTheme(defaultTheme);
120119
}
121120
return false;
@@ -125,7 +124,7 @@ public bool ChangeTheme(string theme)
125124
Log.Error($"|Theme.ChangeTheme|Theme <{theme}> fail to parse");
126125
if (theme != defaultTheme)
127126
{
128-
_api.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_parse_error"), theme));
127+
_api.ShowMsgBox(string.Format(_api.GetTranslation("theme_load_failure_parse_error"), theme));
129128
ChangeTheme(defaultTheme);
130129
}
131130
return false;
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
using System;
22
using System.Globalization;
33
using System.Windows.Data;
4+
using CommunityToolkit.Mvvm.DependencyInjection;
5+
using Flow.Launcher.Plugin;
46

57
namespace Flow.Launcher.Core.Resource
68
{
79
public class TranslationConverter : IValueConverter
810
{
11+
private static readonly IPublicAPI _api = Ioc.Default.GetRequiredService<IPublicAPI>();
12+
913
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1014
{
1115
var key = value.ToString();
12-
if (String.IsNullOrEmpty(key))
16+
if (string.IsNullOrEmpty(key))
1317
return key;
14-
return InternationalizationManager.Instance.GetTranslation(key);
18+
return _api.GetTranslation(key);
1519
}
1620

17-
public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException();
21+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new InvalidOperationException();
1822
}
1923
}

Flow.Launcher.Core/Updater.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Windows;
99
using JetBrains.Annotations;
1010
using Squirrel;
11-
using Flow.Launcher.Core.Resource;
1211
using Flow.Launcher.Plugin.SharedCommands;
1312
using Flow.Launcher.Infrastructure;
1413
using Flow.Launcher.Infrastructure.Http;
@@ -146,8 +145,7 @@ private async Task<UpdateManager> GitHubUpdateManagerAsync(string repository)
146145

147146
public string NewVersionTips(string version)
148147
{
149-
var translator = InternationalizationManager.Instance;
150-
var tips = string.Format(translator.GetTranslation("newVersionTips"), version);
148+
var tips = string.Format(_api.GetTranslation("newVersionTips"), version);
151149

152150
return tips;
153151
}

Flow.Launcher/ActionKeywords.xaml.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
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

75
namespace Flow.Launcher
86
{
97
public partial class ActionKeywords
108
{
119
private readonly PluginPair plugin;
12-
private readonly Internationalization translater = InternationalizationManager.Instance;
1310
private readonly PluginViewModel pluginViewModel;
1411

1512
public ActionKeywords(PluginViewModel pluginViewModel)
@@ -43,7 +40,7 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
4340
}
4441
else
4542
{
46-
string msg = translater.GetTranslation("newActionKeywordsHasBeenAssigned");
43+
string msg = App.API.GetTranslation("newActionKeywordsHasBeenAssigned");
4744
App.API.ShowMsgBox(msg);
4845
}
4946
}

Flow.Launcher/App.xaml.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
9191

9292
AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);
9393

94-
// TODO: Clean InternationalizationManager.Instance and InternationalizationManager.Instance.GetTranslation in future
95-
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
94+
Ioc.Default.GetRequiredService<Internationalization>().ChangeLanguage(_settings.Language);
9695

9796
PluginManager.LoadPlugins(_settings.PluginSettings);
9897

@@ -142,8 +141,7 @@ private void AutoStartup()
142141
// but if it fails (permissions, etc) then don't keep retrying
143142
// this also gives the user a visual indication in the Settings widget
144143
_settings.StartFlowLauncherOnSystemStartup = false;
145-
Notification.Show(InternationalizationManager.Instance.GetTranslation("setAutoStartFailed"),
146-
e.Message);
144+
Notification.Show(API.GetTranslation("setAutoStartFailed"), e.Message);
147145
}
148146
}
149147
}

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();

0 commit comments

Comments
 (0)