From 255f8091a546cc0458a0efd387a2c84465e2379b Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 29 Oct 2021 22:16:13 -0500 Subject: [PATCH 1/4] Add OnCultureInfoChanged to IPluginI18n to allow plugin do action when culture change --- Flow.Launcher.Core/Resource/Internationalization.cs | 6 +++++- Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs | 9 ++++++++- Plugins/Flow.Launcher.Plugin.WindowsSettings/Main.cs | 6 ++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Internationalization.cs b/Flow.Launcher.Core/Resource/Internationalization.cs index 78e8c5cbf23..374f7c71fc8 100644 --- a/Flow.Launcher.Core/Resource/Internationalization.cs +++ b/Flow.Launcher.Core/Resource/Internationalization.cs @@ -10,6 +10,7 @@ using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; using System.Globalization; +using System.Threading.Tasks; namespace Flow.Launcher.Core.Resource { @@ -95,10 +96,13 @@ public void ChangeLanguage(Language language) { LoadLanguage(language); } - UpdatePluginMetadataTranslations(); Settings.Language = language.LanguageCode; CultureInfo.CurrentCulture = new CultureInfo(language.LanguageCode); CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture; + Task.Run(() => + { + UpdatePluginMetadataTranslations(); + }); } public bool PromptShouldUsePinyin(string languageCodeToSet) diff --git a/Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs b/Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs index e332d450eae..e8e861af651 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs @@ -1,4 +1,6 @@ -namespace Flow.Launcher.Plugin +using System.Globalization; + +namespace Flow.Launcher.Plugin { /// /// Represent plugins that support internationalization @@ -8,5 +10,10 @@ public interface IPluginI18n : IFeatures string GetTranslatedPluginTitle(); string GetTranslatedPluginDescription(); + + void OnCultureInfoChanged(CultureInfo newCulture) + { + + } } } \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Main.cs b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Main.cs index b531ac97e2f..491bb903f20 100644 --- a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Main.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Reflection; using Flow.Launcher.Plugin; using Flow.Plugin.WindowsSettings.Classes; @@ -106,6 +107,11 @@ public List Query(Query query) } + public void OnCultureInfoChanged(CultureInfo newCulture) + { + _translatedSettingList = TranslationHelper.TranslateAllSettings(_settingsList); + } + /// /// Return a list context menu entries for a given (shown at the right side of the result). /// From ae2e72b9262096294ae1c2f20479fb11e56774b1 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 29 Oct 2021 22:18:20 -0500 Subject: [PATCH 2/4] add comment --- Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs b/Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs index e8e861af651..61662b671a2 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs @@ -11,6 +11,9 @@ public interface IPluginI18n : IFeatures string GetTranslatedPluginDescription(); + /// + /// The method will be invoked when language of flow changed + /// void OnCultureInfoChanged(CultureInfo newCulture) { From 7cfb71df3586d08f28dff98deef1760402d26b67 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 29 Oct 2021 23:08:59 -0500 Subject: [PATCH 3/4] Change WindowsSettings class to record and use with to create translated setting --- .../Classes/WindowsSetting.cs | 2 +- .../Helper/TranslationHelper.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Classes/WindowsSetting.cs b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Classes/WindowsSetting.cs index 4a130daf746..be7cd44d307 100644 --- a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Classes/WindowsSetting.cs +++ b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Classes/WindowsSetting.cs @@ -9,7 +9,7 @@ namespace Flow.Plugin.WindowsSettings.Classes /// /// A windows setting /// - internal class WindowsSetting + internal record WindowsSetting { /// /// Initializes a new instance of the class. diff --git a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/TranslationHelper.cs b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/TranslationHelper.cs index 48886167fee..529fae0a3c1 100644 --- a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/TranslationHelper.cs +++ b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/TranslationHelper.cs @@ -80,7 +80,7 @@ internal static IEnumerable TranslateAllSettings(in IEnumerable< } } - var translatedSetting = new WindowsSetting + var translatedSetting = settings with { Area = area ?? settings.Area, Name = name ?? settings.Name, From 304fb90c5d526fa08b7df79da3ef9925ebe0d830 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 30 Oct 2021 00:11:17 -0500 Subject: [PATCH 4/4] Expand EnvironmentVariable in Command --- .../Helper/ResultHelper.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ResultHelper.cs b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ResultHelper.cs index 177f1ec0059..c5fd287bda7 100644 --- a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ResultHelper.cs +++ b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ResultHelper.cs @@ -150,12 +150,8 @@ private static bool DoOpenSettingsAction(WindowsSetting entry) ProcessStartInfo processStartInfo; var command = entry.Command; - - if (command.Contains("%windir%", StringComparison.InvariantCultureIgnoreCase)) - { - var windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows); - command = command.Replace("%windir%", windowsFolder, StringComparison.InvariantCultureIgnoreCase); - } + + command = Environment.ExpandEnvironmentVariables(command); if (command.Contains(' ')) {