-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalization.cs
38 lines (33 loc) · 1.22 KB
/
Localization.cs
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
using System;
using System.Windows;
namespace Libertix
{
public static class Localization
{
public static event EventHandler LanguageChanged;
public static void SetLanguage(string cultureName)
{
// Find and remove the current language dictionary (if it exists)
ResourceDictionary oldDict = null;
foreach (ResourceDictionary dict in Application.Current.Resources.MergedDictionaries)
{
if (dict.Source != null && dict.Source.OriginalString.StartsWith("/Resources/Lang/Strings."))
{
oldDict = dict;
break;
}
}
if (oldDict != null)
{
Application.Current.Resources.MergedDictionaries.Remove(oldDict);
}
// Add the new language dictionary
var newDict = new ResourceDictionary
{
Source = new Uri($"pack://application:,,,/Libertix;component/Resources/Lang/Strings.{cultureName}.xaml", UriKind.Absolute)
};
Application.Current.Resources.MergedDictionaries.Add(newDict);
LanguageChanged?.Invoke(null, EventArgs.Empty);
}
}
}