Skip to content

Commit c4b2742

Browse files
committed
add translation method for messages
1 parent 7a7815b commit c4b2742

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
<system:String x:Key="plugin_pluginsmanager_downloading_plugin">Downloading plugin</system:String>
77
<system:String x:Key="plugin_pluginsmanager_please_wait">Please wait...</system:String>
88
<system:String x:Key="plugin_pluginsmanager_download_success">Successfully downloaded</system:String>
9-
<system:String x:Key="plugin_pluginsmanager_uninstall_prompt">Do you want to uninstall the following plugin?</system:String>
9+
<system:String x:Key="plugin_pluginsmanager_uninstall_prompt">Do you want to uninstall the following plugin?{0}{1}{2} by {3}</system:String>
10+
<system:String x:Key="plugin_pluginsmanager_install_prompt">Do you want to install the following plugin?{0}{1}{2} by {3}</system:String>
11+
<system:String x:Key="plugin_pluginsmanager_install_title">Plugin Install</system:String>
12+
<system:String x:Key="plugin_pluginsmanager_uninstall_title">Plugin Uninstall</system:String>
13+
<system:String x:Key="plugin_pluginsmanager_install_errormetadatafile">Install failed: unable to find the plugin.json metadata file from the new plugin</system:String>
14+
<system:String x:Key="plugin_pluginsmanager_install_successandrestart">You have installed plugin {0} successfully.{1}Would you like to restart Flow Launcher to take effect?</system:String>
15+
<system:String x:Key="plugin_pluginsmanager_uninstall_successandrestart">You have uninstalled plugin {0} successfully.{1}Would you like to restart Flow Launcher to take effect?</system:String>
1016
<!--Controls-->
1117

1218
<!--Plugin Infos-->

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,26 @@ internal PluginsManager(PluginInitContext context)
2424
}
2525
internal void InstallOrUpdate(UserPlugin plugin)
2626
{
27-
if (PluginExists(plugin.ID))
27+
if (PluginExists(plugin.ID))
2828
{
29-
var updateMessage = $"Do you want to update following plugin?{Environment.NewLine}{Environment.NewLine}" +
30-
$"Name: {plugin.Name}{Environment.NewLine}" +
31-
$"{Environment.NewLine}New Version: {plugin.Version}" +
32-
$"{Environment.NewLine}Author: {plugin.Author}";
33-
34-
throw new NotImplementedException();
29+
Context.API.ShowMsg("Plugin already installed");
30+
return;
3531
}
3632

37-
var message = $"Do you want to install following plugin?{Environment.NewLine}{Environment.NewLine}" +
38-
$"Name: {plugin.Name}{Environment.NewLine}" +
39-
$"Version: {plugin.Version}{Environment.NewLine}" +
40-
$"Author: {plugin.Author}";
33+
var message = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_prompt"),
34+
Environment.NewLine, Environment.NewLine,
35+
plugin.Name, plugin.Author);
4136

42-
if(MessageBox.Show(message, "Install plugin", MessageBoxButton.YesNo) == MessageBoxResult.No)
37+
if(MessageBox.Show(message, Context.API.GetTranslation("plugin_pluginsmanager_install_title"), MessageBoxButton.YesNo) == MessageBoxResult.No)
4338
return;
4439

4540
var filePath = Path.Combine(DataLocation.PluginsDirectory, $"{plugin.Name}{plugin.ID}.zip");
4641

4742
try
4843
{
44+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
45+
Context.API.GetTranslation("plugin_pluginsmanager_please_wait"));
46+
4947
Utilities.Download(plugin.UrlDownload, filePath);
5048

5149
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
@@ -103,8 +101,6 @@ internal List<Result> RequestInstallOrUpdate(string searchName)
103101
IcoPath = icoPath,
104102
Action = e =>
105103
{
106-
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
107-
Context.API.GetTranslation("plugin_pluginsmanager_please_wait"));
108104
Application.Current.MainWindow.Hide();
109105
InstallOrUpdate(x);
110106

@@ -142,17 +138,18 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
142138

143139
if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath))
144140
{
145-
MessageBox.Show("Install failed: unable to find the plugin.json metadata file from the new plugin");
141+
MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_install_errormetadatafile"));
146142
return;
147143
}
148144

149145
string newPluginPath = Path.Combine(DataLocation.PluginsDirectory, $"{plugin.Name}{plugin.ID}");
150146

151147
Directory.Move(pluginFolderPath, newPluginPath);
152148

153-
if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine}" +
154-
"Restart Flow Launcher to take effect?",
155-
"Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
149+
if (MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_successandrestart"),
150+
plugin.Name, Environment.NewLine),
151+
Context.API.GetTranslation("plugin_pluginsmanager_install_title"),
152+
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
156153
Context.API.RestartApp();
157154
}
158155

@@ -181,18 +178,19 @@ internal List<Result> RequestUninstall(string search)
181178

182179
private void Uninstall(PluginMetadata plugin)
183180
{
184-
string message = Context.API.GetTranslation("plugin_pluginsmanager_uninstall_prompt")+
185-
$"{Environment.NewLine}{Environment.NewLine}" +
186-
$"{plugin.Name} by {plugin.Author}";
181+
string message = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_uninstall_prompt"),
182+
Environment.NewLine, Environment.NewLine,
183+
plugin.Name, plugin.Author);
187184

188-
if (MessageBox.Show(message, "Flow Launcher", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
185+
if (MessageBox.Show(message, Context.API.GetTranslation("plugin_pluginsmanager_uninstall_title"),
186+
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
189187
{
190188
using var _ = File.CreateText(Path.Combine(plugin.PluginDirectory, "NeedDelete.txt"));
191189

192-
var result = MessageBox.Show($"You have uninstalled plugin {plugin.Name} successfully.{Environment.NewLine}" +
193-
"Restart Flow Launcher to take effect?",
194-
"Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question);
195-
if (result == MessageBoxResult.Yes)
190+
if (MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_uninstall_successandrestart"),
191+
plugin.Name, Environment.NewLine),
192+
Context.API.GetTranslation("plugin_pluginsmanager_uninstall_title"),
193+
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
196194
Context.API.RestartApp();
197195
}
198196
}

0 commit comments

Comments
 (0)