-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHumbleKeysLibrarySettingsView.xaml.cs
More file actions
77 lines (65 loc) · 2.92 KB
/
HumbleKeysLibrarySettingsView.xaml.cs
File metadata and controls
77 lines (65 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using Playnite.SDK;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
namespace HumbleKeys
{
public partial class HumbleKeysLibrarySettingsView : UserControl
{
private static readonly ILogger logger = LogManager.GetLogger();
public HumbleKeysLibrarySettingsView()
{
InitializeComponent();
LoadLocalizedResources();
}
private void LoadLocalizedResources()
{
// Get the current culture's ISO language code (e.g., "en", "fr", "es")
//string cultureCode = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
// Get the current culture's country and language code (e.g., "en-US", "fr-FR", "es-ES")
string cultureName = CultureInfo.CurrentUICulture.Name;
if (cultureName == "en-US")
{
// No need to load resources for US English because it is already loaded via XAML (so it works in the designer as well)
return;
}
// Construct the resource dictionary path based on the culture
string resourcePath = $"pack://application:,,,/HumbleKeysLibrary;component/Localization/{cultureName}.xaml";
try
{
// Load the resource dictionary
var resourceDictionary = new ResourceDictionary
{
Source = new Uri(resourcePath, UriKind.Absolute)
};
// Merge the resource dictionary into the UserControl's resources
this.Resources.MergedDictionaries.Clear();
this.Resources.MergedDictionaries.Add(resourceDictionary);
}
catch (Exception ex)
{
// No need to load fallback language because it is already loaded via XAML
/*
// Fallback to default resources (US English) if the specific culture file is not found
string fallbackPath = "pack://application:,,,/HumbleKeysLibrary;component/Localization/en-US.xaml";
var fallbackDictionary = new ResourceDictionary
{
Source = new Uri(fallbackPath, UriKind.Absolute)
};
this.Resources.MergedDictionaries.Clear();
this.Resources.MergedDictionaries.Add(fallbackDictionary);
*/
// Log the error
logger.Warn($"Failed to load resources for culture '{cultureName}': {ex.Message}");
}
}
void ImportChoiceKeys_OnUnchecked(object sender, RoutedEventArgs e)
{
if (!(DataContext is HumbleKeysLibrarySettings model)) return;
if (model.TagWithBundleName != (int)TagMethodology.Monthly) return;
model.TagWithBundleName = (int)TagMethodology.None;
TagMethodCombo.SelectedValue = model.TagWithBundleName;
}
}
}