Skip to content

Commit d0ceea0

Browse files
authored
Merge pull request #781 from Flow-Launcher/translation_new_api
Add OnCultureInfoChanged to IPluginI18n
2 parents 582e296 + 304fb90 commit d0ceea0

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Flow.Launcher.Infrastructure.UserSettings;
1111
using Flow.Launcher.Plugin;
1212
using System.Globalization;
13+
using System.Threading.Tasks;
1314

1415
namespace Flow.Launcher.Core.Resource
1516
{
@@ -95,10 +96,13 @@ public void ChangeLanguage(Language language)
9596
{
9697
LoadLanguage(language);
9798
}
98-
UpdatePluginMetadataTranslations();
9999
Settings.Language = language.LanguageCode;
100100
CultureInfo.CurrentCulture = new CultureInfo(language.LanguageCode);
101101
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
102+
Task.Run(() =>
103+
{
104+
UpdatePluginMetadataTranslations();
105+
});
102106
}
103107

104108
public bool PromptShouldUsePinyin(string languageCodeToSet)

Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Flow.Launcher.Plugin
1+
using System.Globalization;
2+
3+
namespace Flow.Launcher.Plugin
24
{
35
/// <summary>
46
/// Represent plugins that support internationalization
@@ -8,5 +10,13 @@ public interface IPluginI18n : IFeatures
810
string GetTranslatedPluginTitle();
911

1012
string GetTranslatedPluginDescription();
13+
14+
/// <summary>
15+
/// The method will be invoked when language of flow changed
16+
/// </summary>
17+
void OnCultureInfoChanged(CultureInfo newCulture)
18+
{
19+
20+
}
1121
}
1222
}

Plugins/Flow.Launcher.Plugin.WindowsSettings/Classes/WindowsSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Flow.Plugin.WindowsSettings.Classes
99
/// <summary>
1010
/// A windows setting
1111
/// </summary>
12-
internal class WindowsSetting
12+
internal record WindowsSetting
1313
{
1414
/// <summary>
1515
/// Initializes a new instance of the <see cref="WindowsSetting"/> class.

Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ResultHelper.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,8 @@ private static bool DoOpenSettingsAction(WindowsSetting entry)
150150
ProcessStartInfo processStartInfo;
151151

152152
var command = entry.Command;
153-
154-
if (command.Contains("%windir%", StringComparison.InvariantCultureIgnoreCase))
155-
{
156-
var windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
157-
command = command.Replace("%windir%", windowsFolder, StringComparison.InvariantCultureIgnoreCase);
158-
}
153+
154+
command = Environment.ExpandEnvironmentVariables(command);
159155

160156
if (command.Contains(' '))
161157
{

Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/TranslationHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ internal static IEnumerable<WindowsSetting> TranslateAllSettings(in IEnumerable<
8080
}
8181

8282
}
83-
var translatedSetting = new WindowsSetting
83+
var translatedSetting = settings with
8484
{
8585
Area = area ?? settings.Area,
8686
Name = name ?? settings.Name,

Plugins/Flow.Launcher.Plugin.WindowsSettings/Main.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Globalization;
78
using System.Reflection;
89
using Flow.Launcher.Plugin;
910
using Flow.Plugin.WindowsSettings.Classes;
@@ -106,6 +107,11 @@ public List<Result> Query(Query query)
106107

107108
}
108109

110+
public void OnCultureInfoChanged(CultureInfo newCulture)
111+
{
112+
_translatedSettingList = TranslationHelper.TranslateAllSettings(_settingsList);
113+
}
114+
109115
/// <summary>
110116
/// Return a list context menu entries for a given <see cref="Result"/> (shown at the right side of the result).
111117
/// </summary>

0 commit comments

Comments
 (0)