Correctly load plugin localization files

This commit is contained in:
Yusyuriv 2024-06-27 11:05:18 +06:00
parent 597eaa0864
commit d502f1dd25
No known key found for this signature in database
GPG key ID: A91C52E6F73148E0
2 changed files with 9 additions and 7 deletions

View file

@ -203,7 +203,7 @@ namespace Flow.Launcher.Core.Plugin
}
}
InternationalizationManager.Instance.AddPluginLanguageDirectories();
InternationalizationManager.Instance.AddPluginLanguageDirectories(GetPluginsForInterface<IPluginI18n>());
InternationalizationManager.Instance.ChangeLanguage(InternationalizationManager.Instance.Settings.Language);
if (failedPlugins.Any())

View file

@ -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<PluginPair> plugins)
{
foreach (var plugin in PluginManager.GetPluginsForInterface<IPluginI18n>())
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)