From ca970bbe75d914e65791446e5d39c7bffd5d153c Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Sun, 9 Jun 2024 18:45:23 +0600 Subject: [PATCH 1/5] Localize startup messages about missing Python/NodeJS --- .../Environments/AbstractPluginEnvironment.cs | 19 ++++++++++--------- Flow.Launcher.Core/Plugin/PluginManager.cs | 4 ++++ .../Resource/Internationalization.cs | 3 +-- Flow.Launcher/App.xaml.cs | 8 +++----- Flow.Launcher/Languages/en.xaml | 9 +++++++++ Flow.Launcher/Languages/ru.xaml | 8 ++++++++ 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs b/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs index 40eb1be3e..30e812c6f 100644 --- a/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs +++ b/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Forms; +using Flow.Launcher.Core.Resource; namespace Flow.Launcher.Core.ExternalPlugins.Environments { @@ -50,14 +51,15 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments return SetPathForPluginPairs(PluginsSettingsFilePath, Language); } - if (MessageBox.Show($"Flow detected you have installed {Language} plugins, which " + - $"will require {EnvName} to run. Would you like to download {EnvName}? " + - Environment.NewLine + Environment.NewLine + - "Click no if it's already installed, " + - $"and you will be prompted to select the folder that contains the {EnvName} executable", - string.Empty, MessageBoxButtons.YesNo) == DialogResult.No) + var noRuntimeMessage = string.Format( + InternationalizationManager.Instance.GetTranslation("runtimePluginInstalledChooseRuntimePrompt"), + Language, + EnvName, + Environment.NewLine + ); + if (MessageBox.Show(noRuntimeMessage, string.Empty, MessageBoxButtons.YesNo) == DialogResult.No) { - var msg = $"Please select the {EnvName} executable"; + var msg = string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginChooseRuntimeExecutable"), EnvName); string selectedFile; selectedFile = GetFileFromDialog(msg, FileDialogFilter); @@ -80,8 +82,7 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments } else { - MessageBox.Show( - $"Unable to set {Language} executable path, please try from Flow's settings (scroll down to the bottom)."); + MessageBox.Show(string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language)); Log.Error("PluginsLoader", $"Not able to successfully set {EnvName} path, setting's plugin executable path variable is still an empty string.", $"{Language}Environment"); diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index e7dfb31c0..3c8d654fe 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -13,6 +13,7 @@ using Flow.Launcher.Plugin; using ISavable = Flow.Launcher.Plugin.ISavable; using Flow.Launcher.Plugin.SharedCommands; using System.Text.Json; +using Flow.Launcher.Core.Resource; namespace Flow.Launcher.Core.Plugin { @@ -160,6 +161,9 @@ namespace Flow.Launcher.Core.Plugin } } + InternationalizationManager.Instance.AddPluginLanguageDirectories(); + InternationalizationManager.Instance.ChangeLanguage(InternationalizationManager.Instance.Settings.Language); + if (failedPlugins.Any()) { var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name)); diff --git a/Flow.Launcher.Core/Resource/Internationalization.cs b/Flow.Launcher.Core/Resource/Internationalization.cs index 06eb868b8..741cb9f3b 100644 --- a/Flow.Launcher.Core/Resource/Internationalization.cs +++ b/Flow.Launcher.Core/Resource/Internationalization.cs @@ -25,7 +25,6 @@ namespace Flow.Launcher.Core.Resource public Internationalization() { - AddPluginLanguageDirectories(); LoadDefaultLanguage(); // we don't want to load /Languages/en.xaml twice // so add flowlauncher language directory after load plugin language files @@ -40,7 +39,7 @@ namespace Flow.Launcher.Core.Resource } - private void AddPluginLanguageDirectories() + internal void AddPluginLanguageDirectories() { foreach (var plugin in PluginManager.GetPluginsForInterface()) { diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 765a1a559..4d1adc6cd 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -71,6 +71,9 @@ namespace Flow.Launcher StringMatcher.Instance = _stringMatcher; _stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision; + InternationalizationManager.Instance.Settings = _settings; + InternationalizationManager.Instance.ChangeLanguage(_settings.Language); + PluginManager.LoadPlugins(_settings.PluginSettings); _mainVM = new MainViewModel(_settings); @@ -89,11 +92,6 @@ namespace Flow.Launcher Current.MainWindow = window; Current.MainWindow.Title = Constant.FlowLauncher; - // todo temp fix for instance code logic - // load plugin before change language, because plugin language also needs be changed - InternationalizationManager.Instance.Settings = _settings; - InternationalizationManager.Instance.ChangeLanguage(_settings.Language); - HotKeyMapper.Initialize(_mainVM); // main windows needs initialized before theme change because of blur settings diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 83831a398..700e60933 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -2,6 +2,15 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib"> + + + Flow detected you have installed {0} plugins, which will require {1} to run. Would you like to download {1}? + {2}{2} + Click no if it's already installed, and you will be prompted to select the folder that contains the {1} executable + + Please select the {0} executable + Unable to set {0} executable path, please try from Flow's settings (scroll down to the bottom). + Failed to register hotkey "{0}". The hotkey may be in use by another program. Change to a different hotkey, or exit another program. Flow Launcher diff --git a/Flow.Launcher/Languages/ru.xaml b/Flow.Launcher/Languages/ru.xaml index 739252da7..74d9ded0f 100644 --- a/Flow.Launcher/Languages/ru.xaml +++ b/Flow.Launcher/Languages/ru.xaml @@ -3,6 +3,14 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib"> + + + Flow определил, что вы установили {0} плагины, которым требуется {1} для работы. Скачать {1}? + {2}{2} + Кликните нет, если он уже установлен, и вам будет предложено выбрать папку, где находится исполняемый файл {1} + + Please select the {0} executable + Unable to set {0} executable path, please try from Flow's settings (scroll down to the bottom). Не удалось зарегистрировать сочетание клавиш "{0}". Возможно, оно используется другой программой. Измените сочетание клавиш или закройте другую программу. Flow Launcher From d502f1dd25c17ba3cff9312aecd2446e02936b06 Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Thu, 27 Jun 2024 11:05:18 +0600 Subject: [PATCH 2/5] Correctly load plugin localization files --- Flow.Launcher.Core/Plugin/PluginManager.cs | 2 +- .../Resource/Internationalization.cs | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index b78331690..8c73ae400 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -203,7 +203,7 @@ namespace Flow.Launcher.Core.Plugin } } - InternationalizationManager.Instance.AddPluginLanguageDirectories(); + InternationalizationManager.Instance.AddPluginLanguageDirectories(GetPluginsForInterface()); InternationalizationManager.Instance.ChangeLanguage(InternationalizationManager.Instance.Settings.Language); if (failedPlugins.Any()) diff --git a/Flow.Launcher.Core/Resource/Internationalization.cs b/Flow.Launcher.Core/Resource/Internationalization.cs index 741cb9f3b..192ed2e81 100644 --- a/Flow.Launcher.Core/Resource/Internationalization.cs +++ b/Flow.Launcher.Core/Resource/Internationalization.cs @@ -25,9 +25,6 @@ namespace Flow.Launcher.Core.Resource public Internationalization() { - LoadDefaultLanguage(); - // we don't want to load /Languages/en.xaml twice - // so add flowlauncher language directory after load plugin language files AddFlowLauncherLanguageDirectory(); } @@ -39,9 +36,9 @@ namespace Flow.Launcher.Core.Resource } - internal void AddPluginLanguageDirectories() + internal void AddPluginLanguageDirectories(IEnumerable plugins) { - foreach (var plugin in PluginManager.GetPluginsForInterface()) + foreach (var plugin in plugins) { var location = Assembly.GetAssembly(plugin.Plugin.GetType()).Location; var dir = Path.GetDirectoryName(location); @@ -55,6 +52,8 @@ namespace Flow.Launcher.Core.Resource Log.Error($"|Internationalization.AddPluginLanguageDirectories|Can't find plugin path <{location}> for <{plugin.Metadata.Name}>"); } } + + LoadDefaultLanguage(); } private void LoadDefaultLanguage() @@ -139,11 +138,14 @@ namespace Flow.Launcher.Core.Resource private void LoadLanguage(Language language) { + var flowEnglishFile = Path.Combine(Constant.ProgramDirectory, Folder, DefaultFile); var dicts = Application.Current.Resources.MergedDictionaries; var filename = $"{language.LanguageCode}{Extension}"; var files = _languageDirectories .Select(d => LanguageFile(d, filename)) - .Where(f => !string.IsNullOrEmpty(f)) + // Exclude Flow's English language file since it's built into the binary, and there's no need to load + // it again from the file system. + .Where(f => !string.IsNullOrEmpty(f) && f != flowEnglishFile) .ToArray(); if (files.Length > 0) From bfd8dfe2e133b50a3cac672c268c707713d1ec8a Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Thu, 27 Jun 2024 11:10:12 +0600 Subject: [PATCH 3/5] Localize plugin init fail message --- Flow.Launcher.Core/Plugin/PluginManager.cs | 12 +++++++++--- Flow.Launcher/Languages/en.xaml | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 8c73ae400..2d13f7d7f 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -209,9 +209,15 @@ namespace Flow.Launcher.Core.Plugin if (failedPlugins.Any()) { var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name)); - API.ShowMsg($"Fail to Init Plugins", - $"Plugins: {failed} - fail to load and would be disabled, please contact plugin creator for help", - "", false); + API.ShowMsg( + InternationalizationManager.Instance.GetTranslation("failedToInitializePluginsTitle"), + string.Format( + InternationalizationManager.Instance.GetTranslation("failedToInitializePluginsMessage"), + failed + ), + "", + false + ); } } diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 3844ccf11..2f11f118b 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -10,6 +10,8 @@ Please select the {0} executable Unable to set {0} executable path, please try from Flow's settings (scroll down to the bottom). + Fail to Init Plugins + Plugins: {0} - fail to load and would be disabled, please contact plugin creator for help Failed to register hotkey "{0}". The hotkey may be in use by another program. Change to a different hotkey, or exit another program. From 1c2d9e8f52d0d617baf10dd3e2a9096d4c2fcd36 Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Thu, 27 Jun 2024 11:10:50 +0600 Subject: [PATCH 4/5] Remove unnecessary spaces --- Flow.Launcher.Core/Plugin/PluginManager.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 2d13f7d7f..f5fa5e518 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -52,7 +52,7 @@ namespace Flow.Launcher.Core.Plugin } /// - /// Save json and ISavable + /// Save json and ISavable /// public static void Save() { @@ -225,11 +225,11 @@ namespace Flow.Launcher.Core.Plugin { if (query is null) return Array.Empty(); - + if (!NonGlobalPlugins.ContainsKey(query.ActionKeyword)) return GlobalPlugins; - - + + var plugin = NonGlobalPlugins[query.ActionKeyword]; return new List { @@ -289,8 +289,8 @@ namespace Flow.Launcher.Core.Plugin r.PluginID = metadata.ID; r.OriginQuery = query; - // ActionKeywordAssigned is used for constructing MainViewModel's query text auto-complete suggestions - // Plugins may have multi-actionkeywords eg. WebSearches. In this scenario it needs to be overriden on the plugin level + // ActionKeywordAssigned is used for constructing MainViewModel's query text auto-complete suggestions + // Plugins may have multi-actionkeywords eg. WebSearches. In this scenario it needs to be overriden on the plugin level if (metadata.ActionKeywords.Count == 1) r.ActionKeywordAssigned = query.ActionKeyword; } @@ -473,7 +473,7 @@ namespace Flow.Launcher.Core.Plugin // Unzip plugin files to temp folder var tempFolderPluginPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, tempFolderPluginPath); - + if(!plugin.IsFromLocalInstallPath) File.Delete(zipFilePath); From c9ec16549e0344daa21cbd824a17bc2bf4724637 Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Thu, 27 Jun 2024 11:33:03 +0600 Subject: [PATCH 5/5] Fix untranslated Russian strings --- Flow.Launcher/Languages/ru.xaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/Languages/ru.xaml b/Flow.Launcher/Languages/ru.xaml index c733018ac..b94b1f540 100644 --- a/Flow.Launcher/Languages/ru.xaml +++ b/Flow.Launcher/Languages/ru.xaml @@ -9,8 +9,8 @@ {2}{2} Кликните нет, если он уже установлен, и вам будет предложено выбрать папку, где находится исполняемый файл {1} - Please select the {0} executable - Unable to set {0} executable path, please try from Flow's settings (scroll down to the bottom). + Пожалуйста, выберите исполняемый файл {0} + Не удалось установить путь к исполняемому файлу {0}, пожалуйста, попробуйте через настройки Flow (прокрутите вниз). Не удалось зарегистрировать сочетание клавиш "{0}". Возможно, оно используется другой программой. Измените сочетание клавиш или закройте другую программу. Flow Launcher