Skip to content

Commit 39f6cd6

Browse files
authored
Merge pull request #2769 from Flow-Launcher/localize-missing-python-js-dialog
Localize startup messages about missing Python/NodeJS
2 parents 08af45f + b0dfeaf commit 39f6cd6

File tree

6 files changed

+60
-31
lines changed

6 files changed

+60
-31
lines changed

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.IO;
88
using System.Linq;
99
using System.Windows.Forms;
10+
using Flow.Launcher.Core.Resource;
1011

1112
namespace Flow.Launcher.Core.ExternalPlugins.Environments
1213
{
@@ -50,14 +51,15 @@ internal IEnumerable<PluginPair> Setup()
5051
return SetPathForPluginPairs(PluginsSettingsFilePath, Language);
5152
}
5253

53-
if (MessageBox.Show($"Flow detected you have installed {Language} plugins, which " +
54-
$"will require {EnvName} to run. Would you like to download {EnvName}? " +
55-
Environment.NewLine + Environment.NewLine +
56-
"Click no if it's already installed, " +
57-
$"and you will be prompted to select the folder that contains the {EnvName} executable",
58-
string.Empty, MessageBoxButtons.YesNo) == DialogResult.No)
54+
var noRuntimeMessage = string.Format(
55+
InternationalizationManager.Instance.GetTranslation("runtimePluginInstalledChooseRuntimePrompt"),
56+
Language,
57+
EnvName,
58+
Environment.NewLine
59+
);
60+
if (MessageBox.Show(noRuntimeMessage, string.Empty, MessageBoxButtons.YesNo) == DialogResult.No)
5961
{
60-
var msg = $"Please select the {EnvName} executable";
62+
var msg = string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginChooseRuntimeExecutable"), EnvName);
6163
string selectedFile;
6264

6365
selectedFile = GetFileFromDialog(msg, FileDialogFilter);
@@ -80,8 +82,7 @@ internal IEnumerable<PluginPair> Setup()
8082
}
8183
else
8284
{
83-
MessageBox.Show(
84-
$"Unable to set {Language} executable path, please try from Flow's settings (scroll down to the bottom).");
85+
MessageBox.Show(string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language));
8586
Log.Error("PluginsLoader",
8687
$"Not able to successfully set {EnvName} path, setting's plugin executable path variable is still an empty string.",
8788
$"{Language}Environment");

Flow.Launcher.Core/Plugin/PluginManager.cs

+20-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using ISavable = Flow.Launcher.Plugin.ISavable;
1414
using Flow.Launcher.Plugin.SharedCommands;
1515
using System.Text.Json;
16+
using Flow.Launcher.Core.Resource;
1617

1718
namespace Flow.Launcher.Core.Plugin
1819
{
@@ -51,7 +52,7 @@ private static void DeletePythonBinding()
5152
}
5253

5354
/// <summary>
54-
/// Save json and ISavable
55+
/// Save json and ISavable
5556
/// </summary>
5657
public static void Save()
5758
{
@@ -202,24 +203,33 @@ public static async Task InitializePluginsAsync(IPublicAPI api)
202203
}
203204
}
204205

206+
InternationalizationManager.Instance.AddPluginLanguageDirectories(GetPluginsForInterface<IPluginI18n>());
207+
InternationalizationManager.Instance.ChangeLanguage(InternationalizationManager.Instance.Settings.Language);
208+
205209
if (failedPlugins.Any())
206210
{
207211
var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name));
208-
API.ShowMsg($"Fail to Init Plugins",
209-
$"Plugins: {failed} - fail to load and would be disabled, please contact plugin creator for help",
210-
"", false);
212+
API.ShowMsg(
213+
InternationalizationManager.Instance.GetTranslation("failedToInitializePluginsTitle"),
214+
string.Format(
215+
InternationalizationManager.Instance.GetTranslation("failedToInitializePluginsMessage"),
216+
failed
217+
),
218+
"",
219+
false
220+
);
211221
}
212222
}
213223

214224
public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
215225
{
216226
if (query is null)
217227
return Array.Empty<PluginPair>();
218-
228+
219229
if (!NonGlobalPlugins.ContainsKey(query.ActionKeyword))
220230
return GlobalPlugins;
221-
222-
231+
232+
223233
var plugin = NonGlobalPlugins[query.ActionKeyword];
224234
return new List<PluginPair>
225235
{
@@ -279,8 +289,8 @@ public static void UpdatePluginMetadata(List<Result> results, PluginMetadata met
279289
r.PluginID = metadata.ID;
280290
r.OriginQuery = query;
281291

282-
// ActionKeywordAssigned is used for constructing MainViewModel's query text auto-complete suggestions
283-
// Plugins may have multi-actionkeywords eg. WebSearches. In this scenario it needs to be overriden on the plugin level
292+
// ActionKeywordAssigned is used for constructing MainViewModel's query text auto-complete suggestions
293+
// Plugins may have multi-actionkeywords eg. WebSearches. In this scenario it needs to be overriden on the plugin level
284294
if (metadata.ActionKeywords.Count == 1)
285295
r.ActionKeywordAssigned = query.ActionKeyword;
286296
}
@@ -463,7 +473,7 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
463473
// Unzip plugin files to temp folder
464474
var tempFolderPluginPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
465475
System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, tempFolderPluginPath);
466-
476+
467477
if(!plugin.IsFromLocalInstallPath)
468478
File.Delete(zipFilePath);
469479

Flow.Launcher.Core/Resource/Internationalization.cs

+8-7
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ public class Internationalization
2525

2626
public Internationalization()
2727
{
28-
AddPluginLanguageDirectories();
29-
LoadDefaultLanguage();
30-
// we don't want to load /Languages/en.xaml twice
31-
// so add flowlauncher language directory after load plugin language files
3228
AddFlowLauncherLanguageDirectory();
3329
}
3430

@@ -40,9 +36,9 @@ private void AddFlowLauncherLanguageDirectory()
4036
}
4137

4238

43-
private void AddPluginLanguageDirectories()
39+
internal void AddPluginLanguageDirectories(IEnumerable<PluginPair> plugins)
4440
{
45-
foreach (var plugin in PluginManager.GetPluginsForInterface<IPluginI18n>())
41+
foreach (var plugin in plugins)
4642
{
4743
var location = Assembly.GetAssembly(plugin.Plugin.GetType()).Location;
4844
var dir = Path.GetDirectoryName(location);
@@ -56,6 +52,8 @@ private void AddPluginLanguageDirectories()
5652
Log.Error($"|Internationalization.AddPluginLanguageDirectories|Can't find plugin path <{location}> for <{plugin.Metadata.Name}>");
5753
}
5854
}
55+
56+
LoadDefaultLanguage();
5957
}
6058

6159
private void LoadDefaultLanguage()
@@ -140,11 +138,14 @@ private void RemoveOldLanguageFiles()
140138

141139
private void LoadLanguage(Language language)
142140
{
141+
var flowEnglishFile = Path.Combine(Constant.ProgramDirectory, Folder, DefaultFile);
143142
var dicts = Application.Current.Resources.MergedDictionaries;
144143
var filename = $"{language.LanguageCode}{Extension}";
145144
var files = _languageDirectories
146145
.Select(d => LanguageFile(d, filename))
147-
.Where(f => !string.IsNullOrEmpty(f))
146+
// Exclude Flow's English language file since it's built into the binary, and there's no need to load
147+
// it again from the file system.
148+
.Where(f => !string.IsNullOrEmpty(f) && f != flowEnglishFile)
148149
.ToArray();
149150

150151
if (files.Length > 0)

Flow.Launcher/App.xaml.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
7171
StringMatcher.Instance = _stringMatcher;
7272
_stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision;
7373

74+
InternationalizationManager.Instance.Settings = _settings;
75+
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
76+
7477
PluginManager.LoadPlugins(_settings.PluginSettings);
7578
_mainVM = new MainViewModel(_settings);
7679

@@ -89,11 +92,6 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
8992
Current.MainWindow = window;
9093
Current.MainWindow.Title = Constant.FlowLauncher;
9194

92-
// todo temp fix for instance code logic
93-
// load plugin before change language, because plugin language also needs be changed
94-
InternationalizationManager.Instance.Settings = _settings;
95-
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
96-
9795
HotKeyMapper.Initialize(_mainVM);
9896

9997
// main windows needs initialized before theme change because of blur settings

Flow.Launcher/Languages/en.xaml

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:system="clr-namespace:System;assembly=mscorlib">
5+
<!-- Startup -->
6+
<system:String x:Key="runtimePluginInstalledChooseRuntimePrompt">
7+
Flow detected you have installed {0} plugins, which will require {1} to run. Would you like to download {1}?
8+
{2}{2}
9+
Click no if it's already installed, and you will be prompted to select the folder that contains the {1} executable
10+
</system:String>
11+
<system:String x:Key="runtimePluginChooseRuntimeExecutable">Please select the {0} executable</system:String>
12+
<system:String x:Key="runtimePluginUnableToSetExecutablePath">Unable to set {0} executable path, please try from Flow's settings (scroll down to the bottom).</system:String>
13+
<system:String x:Key="failedToInitializePluginsTitle">Fail to Init Plugins</system:String>
14+
<system:String x:Key="failedToInitializePluginsMessage">Plugins: {0} - fail to load and would be disabled, please contact plugin creator for help</system:String>
15+
516
<!-- MainWindow -->
617
<system:String x:Key="registerHotkeyFailed">Failed to register hotkey "{0}". The hotkey may be in use by another program. Change to a different hotkey, or exit another program.</system:String>
718
<system:String x:Key="MessageBoxTitle">Flow Launcher</system:String>

Flow.Launcher/Languages/ru.xaml

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:system="clr-namespace:System;assembly=mscorlib">
6+
<!-- Startup -->
7+
<system:String x:Key="runtimePluginInstalledChooseRuntimePrompt">
8+
Flow определил, что вы установили {0} плагины, которым требуется {1} для работы. Скачать {1}?
9+
{2}{2}
10+
Кликните нет, если он уже установлен, и вам будет предложено выбрать папку, где находится исполняемый файл {1}
11+
</system:String>
12+
<system:String x:Key="runtimePluginChooseRuntimeExecutable">Пожалуйста, выберите исполняемый файл {0}</system:String>
13+
<system:String x:Key="runtimePluginUnableToSetExecutablePath">Не удалось установить путь к исполняемому файлу {0}, пожалуйста, попробуйте через настройки Flow (прокрутите вниз).</system:String>
614
<!-- MainWindow -->
715
<system:String x:Key="registerHotkeyFailed">Не удалось зарегистрировать сочетание клавиш &quot;{0}&quot;. Возможно, оно используется другой программой. Измените сочетание клавиш или закройте другую программу.</system:String>
816
<system:String x:Key="MessageBoxTitle">Flow Launcher</system:String>

0 commit comments

Comments
 (0)