aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Ava/Common/Locale
diff options
context:
space:
mode:
authorEmmanuel Hansen <emmausssss@gmail.com>2023-01-03 18:45:08 +0000
committerGitHub <noreply@github.com>2023-01-03 19:45:08 +0100
commit02714a1291e1b548908ffd7adcd537897bf6f541 (patch)
tree4c0aec3e5024115bb994811067733528345b9234 /Ryujinx.Ava/Common/Locale
parent09c9686498c7c987c94f33c79732c7592045e035 (diff)
Avalonia - Add source generator for locale items (#3999)
* Add source generator for locale keys * use locale keys in Ui subdir
Diffstat (limited to 'Ryujinx.Ava/Common/Locale')
-rw-r--r--Ryujinx.Ava/Common/Locale/LocaleExtension.cs6
-rw-r--r--Ryujinx.Ava/Common/Locale/LocaleManager.cs22
2 files changed, 16 insertions, 12 deletions
diff --git a/Ryujinx.Ava/Common/Locale/LocaleExtension.cs b/Ryujinx.Ava/Common/Locale/LocaleExtension.cs
index 8fca1a00..6c54becd 100644
--- a/Ryujinx.Ava/Common/Locale/LocaleExtension.cs
+++ b/Ryujinx.Ava/Common/Locale/LocaleExtension.cs
@@ -7,16 +7,16 @@ namespace Ryujinx.Ava.Common.Locale
{
internal class LocaleExtension : MarkupExtension
{
- public LocaleExtension(string key)
+ public LocaleExtension(LocaleKeys key)
{
Key = key;
}
- public string Key { get; }
+ public LocaleKeys Key { get; }
public override object ProvideValue(IServiceProvider serviceProvider)
{
- string keyToUse = Key;
+ LocaleKeys keyToUse = Key;
ReflectionBindingExtension binding = new($"[{keyToUse}]")
{
diff --git a/Ryujinx.Ava/Common/Locale/LocaleManager.cs b/Ryujinx.Ava/Common/Locale/LocaleManager.cs
index acbbf2df..c2251f85 100644
--- a/Ryujinx.Ava/Common/Locale/LocaleManager.cs
+++ b/Ryujinx.Ava/Common/Locale/LocaleManager.cs
@@ -2,6 +2,7 @@
using Ryujinx.Common;
using Ryujinx.Common.Utilities;
using Ryujinx.Ui.Common.Configuration;
+using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
@@ -13,17 +14,17 @@ namespace Ryujinx.Ava.Common.Locale
{
private const string DefaultLanguageCode = "en_US";
- private Dictionary<string, string> _localeStrings;
- private ConcurrentDictionary<string, object[]> _dynamicValues;
+ private Dictionary<LocaleKeys, string> _localeStrings;
+ private ConcurrentDictionary<LocaleKeys, object[]> _dynamicValues;
public static LocaleManager Instance { get; } = new LocaleManager();
- public Dictionary<string, string> LocaleStrings { get => _localeStrings; set => _localeStrings = value; }
+ public Dictionary<LocaleKeys, string> LocaleStrings { get => _localeStrings; set => _localeStrings = value; }
public LocaleManager()
{
- _localeStrings = new Dictionary<string, string>();
- _dynamicValues = new ConcurrentDictionary<string, object[]>();
+ _localeStrings = new Dictionary<LocaleKeys, string>();
+ _dynamicValues = new ConcurrentDictionary<LocaleKeys, object[]>();
Load();
}
@@ -49,7 +50,7 @@ namespace Ryujinx.Ava.Common.Locale
}
}
- public string this[string key]
+ public string this[LocaleKeys key]
{
get
{
@@ -63,7 +64,7 @@ namespace Ryujinx.Ava.Common.Locale
return value;
}
- return key;
+ return key.ToString();
}
set
{
@@ -73,7 +74,7 @@ namespace Ryujinx.Ava.Common.Locale
}
}
- public void UpdateDynamicValue(string key, params object[] values)
+ public void UpdateDynamicValue(LocaleKeys key, params object[] values)
{
_dynamicValues[key] = values;
@@ -98,7 +99,10 @@ namespace Ryujinx.Ava.Common.Locale
foreach (var item in strings)
{
- this[item.Key] = item.Value;
+ if (Enum.TryParse<LocaleKeys>(item.Key, out var key))
+ {
+ this[key] = item.Value;
+ }
}
if (Program.PreviewerDetached)