Change GetLanguageDictionary method to LanguageDictionary property

This commit is contained in:
Stone_Red
2024-12-30 16:54:04 +01:00
parent b638eff451
commit ead20d1279
6 changed files with 37 additions and 34 deletions
+20 -17
View File
@@ -66,6 +66,26 @@ public partial class App : Application
}
};
public static ResourceDictionary LanguageDictionary
{
get
{
ResourceDictionary dict = [];
string currentCulture = Thread.CurrentThread.CurrentUICulture.ToString();
if (currentCulture.Contains("de"))
{
dict.Source = new Uri("..\\Resources\\Strings\\StringResources.de.xaml", UriKind.Relative);
}
else
{
dict.Source = new Uri("..\\Resources\\Strings\\StringResources.en.xaml", UriKind.Relative);
}
return dict;
}
}
private static string PreviousApplicationDataPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "StoneRed", PreviousAppName);
public App()
@@ -98,23 +118,6 @@ public partial class App : Application
}
}
public static ResourceDictionary GetLanguageDictionary()
{
ResourceDictionary dict = [];
string currentCulture = Thread.CurrentThread.CurrentUICulture.ToString();
if (currentCulture.Contains("de"))
{
dict.Source = new Uri("..\\Resources\\Strings\\StringResources.de.xaml", UriKind.Relative);
}
else
{
dict.Source = new Uri("..\\Resources\\Strings\\StringResources.en.xaml", UriKind.Relative);
}
return dict;
}
protected void CloseHandler(object sender, EventArgs e)
{
eventWaitHandle.Close();
@@ -22,9 +22,9 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co
public string? Description => pluginMetadata.Description;
public string Author => pluginMetadata.Author ?? (string)App.GetLanguageDictionary()["unknown"];
public string Author => pluginMetadata.Author ?? (string)App.LanguageDictionary["unknown"];
public string? Version => pluginMetadata.Version ?? (string)App.GetLanguageDictionary()["unknown"];
public string? Version => pluginMetadata.Version ?? (string)App.LanguageDictionary["unknown"];
public string? Logo => pluginMetadata.IconUri?.ToString();
@@ -43,7 +43,7 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co
{
if (string.IsNullOrWhiteSpace(pluginMetadata.ProfileUri?.ToString()))
{
return new(PackIconKind.FolderOutline, (string)App.GetLanguageDictionary()["folder"], path is not null, new CommandHandler(() => Process.Start("explorer.exe", path!)));
return new(PackIconKind.FolderOutline, (string)App.LanguageDictionary["folder"], path is not null, new CommandHandler(() => Process.Start("explorer.exe", path!)));
}
else
{
@@ -80,8 +80,8 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co
{
return mode switch
{
Mode.Install => (string)App.GetLanguageDictionary()["install"],
Mode.Uninstall => (string)App.GetLanguageDictionary()["uninstall"],
Mode.Install => (string)App.LanguageDictionary["install"],
Mode.Uninstall => (string)App.LanguageDictionary["uninstall"],
_ => throw new NotImplementedException()
};
}
+1 -1
View File
@@ -19,7 +19,7 @@ public partial class ColorDialog : Window
{
InitializeComponent();
Resources.MergedDictionaries.Add(App.GetLanguageDictionary());
Resources.MergedDictionaries.Add(App.LanguageDictionary);
label.Content = content;
Title = title;
+1 -1
View File
@@ -14,7 +14,7 @@ public partial class InputDialog : Window
{
InitializeComponent();
Resources.MergedDictionaries.Add(App.GetLanguageDictionary());
Resources.MergedDictionaries.Add(App.LanguageDictionary);
label.Content = content;
Title = title;
+9 -9
View File
@@ -26,10 +26,10 @@ namespace DesktopMagic
private readonly Dictionary<PluginMetadata, Type> builtInPlugins = new()
{
{new((string)App.GetLanguageDictionary()["musicVisualizer"], 1), typeof(MusicVisualizerPlugin)},
{new((string)App.GetLanguageDictionary()["time"],2), typeof(TimePlugin)},
{new((string)App.GetLanguageDictionary()["date"],3), typeof(DatePlugin)},
{new((string)App.GetLanguageDictionary()["cpuUsage"], 4), typeof(CpuMonitorPlugin)}
{new((string)App.LanguageDictionary["musicVisualizer"], 1), typeof(MusicVisualizerPlugin)},
{new((string)App.LanguageDictionary["time"],2), typeof(TimePlugin)},
{new((string)App.LanguageDictionary["date"],3), typeof(DatePlugin)},
{new((string)App.LanguageDictionary["cpuUsage"], 4), typeof(CpuMonitorPlugin)}
};
private bool loaded = false;
@@ -58,17 +58,17 @@ namespace DesktopMagic
{
Items =
{
new System.Windows.Forms.ToolStripMenuItem((string)App.GetLanguageDictionary()["open"], null, (s, e) => RestoreWindow()),
new System.Windows.Forms.ToolStripMenuItem((string)App.GetLanguageDictionary()["toggleEditMode"], null, (s, e) => { EditCheckBox.IsChecked = !EditCheckBox.IsChecked; EditCheckBox_Click(null, null); }),
new System.Windows.Forms.ToolStripMenuItem((string)App.GetLanguageDictionary()["pluginManager"], null, (s, e) => PluginManagerButton_Click(null!, null!)),
new System.Windows.Forms.ToolStripMenuItem((string)App.LanguageDictionary["open"], null, (s, e) => RestoreWindow()),
new System.Windows.Forms.ToolStripMenuItem((string)App.LanguageDictionary ["toggleEditMode"], null, (s, e) => { EditCheckBox.IsChecked = !EditCheckBox.IsChecked; EditCheckBox_Click(null, null); }),
new System.Windows.Forms.ToolStripMenuItem((string)App.LanguageDictionary["pluginManager"], null, (s, e) => PluginManagerButton_Click(null!, null!)),
new System.Windows.Forms.ToolStripMenuItem("GitHub", null, (s, e) => GitHubButton_Click(null!, null!)),
new System.Windows.Forms.ToolStripMenuItem((string)App.GetLanguageDictionary()["quit"], null, (s, e) => Quit()),
new System.Windows.Forms.ToolStripMenuItem((string)App.LanguageDictionary["quit"], null, (s, e) => Quit()),
}
};
InitializeComponent();
Resources.MergedDictionaries.Add(App.GetLanguageDictionary());
Resources.MergedDictionaries.Add(App.LanguageDictionary);
#if DEBUG
Title = $"{App.AppName} - Dev {System.Windows.Forms.Application.ProductVersion}";
@@ -44,7 +44,7 @@ public partial class PluginManager : Window
{
InitializeComponent();
Resources.MergedDictionaries.Add(App.GetLanguageDictionary());
Resources.MergedDictionaries.Add(App.LanguageDictionary);
DataContext = pluginManagerDataContext;
searchTimer.Tick += async (sender, e) =>