aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Ava/Common
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
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')
-rw-r--r--Ryujinx.Ava/Common/ApplicationHelper.cs22
-rw-r--r--Ryujinx.Ava/Common/Locale/LocaleExtension.cs6
-rw-r--r--Ryujinx.Ava/Common/Locale/LocaleManager.cs22
3 files changed, 27 insertions, 23 deletions
diff --git a/Ryujinx.Ava/Common/ApplicationHelper.cs b/Ryujinx.Ava/Common/ApplicationHelper.cs
index 0c562dfe..8e5bdaec 100644
--- a/Ryujinx.Ava/Common/ApplicationHelper.cs
+++ b/Ryujinx.Ava/Common/ApplicationHelper.cs
@@ -81,7 +81,7 @@ namespace Ryujinx.Ava.Common
Dispatcher.UIThread.Post(async () =>
{
await ContentDialogHelper.CreateErrorDialog(
- string.Format(LocaleManager.Instance["DialogMessageCreateSaveErrorMessage"], result.ToStringWithName()));
+ string.Format(LocaleManager.Instance[LocaleKeys.DialogMessageCreateSaveErrorMessage], result.ToStringWithName()));
});
return false;
@@ -100,7 +100,7 @@ namespace Ryujinx.Ava.Common
Dispatcher.UIThread.Post(async () =>
{
- await ContentDialogHelper.CreateErrorDialog(string.Format(LocaleManager.Instance["DialogMessageFindSaveErrorMessage"], result.ToStringWithName()));
+ await ContentDialogHelper.CreateErrorDialog(string.Format(LocaleManager.Instance[LocaleKeys.DialogMessageFindSaveErrorMessage], result.ToStringWithName()));
});
return false;
@@ -151,7 +151,7 @@ namespace Ryujinx.Ava.Common
public static async Task ExtractSection(NcaSectionType ncaSectionType, string titleFilePath,
int programIndex = 0)
{
- OpenFolderDialog folderDialog = new() { Title = LocaleManager.Instance["FolderDialogExtractTitle"] };
+ OpenFolderDialog folderDialog = new() { Title = LocaleManager.Instance[LocaleKeys.FolderDialogExtractTitle] };
string destination = await folderDialog.ShowAsync(_owner);
@@ -164,11 +164,11 @@ namespace Ryujinx.Ava.Common
Dispatcher.UIThread.Post(async () =>
{
UserResult result = await ContentDialogHelper.CreateConfirmationDialog(
- string.Format(LocaleManager.Instance["DialogNcaExtractionMessage"], ncaSectionType, Path.GetFileName(titleFilePath)),
+ string.Format(LocaleManager.Instance[LocaleKeys.DialogNcaExtractionMessage], ncaSectionType, Path.GetFileName(titleFilePath)),
"",
"",
- LocaleManager.Instance["InputDialogCancel"],
- LocaleManager.Instance["DialogNcaExtractionTitle"]);
+ LocaleManager.Instance[LocaleKeys.InputDialogCancel],
+ LocaleManager.Instance[LocaleKeys.DialogNcaExtractionTitle]);
if (result == UserResult.Cancel)
{
@@ -234,7 +234,7 @@ namespace Ryujinx.Ava.Common
"Extraction failure. The main NCA was not present in the selected file");
Dispatcher.UIThread.InvokeAsync(async () =>
{
- await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance["DialogNcaExtractionMainNcaNotFoundErrorMessage"]);
+ await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogNcaExtractionMainNcaNotFoundErrorMessage]);
});
return;
}
@@ -275,7 +275,7 @@ namespace Ryujinx.Ava.Common
$"LibHac returned error code: {resultCode.Value.ErrorCode}");
Dispatcher.UIThread.InvokeAsync(async () =>
{
- await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance["DialogNcaExtractionCheckLogErrorMessage"]);
+ await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogNcaExtractionCheckLogErrorMessage]);
});
}
else if (resultCode.Value.IsSuccess())
@@ -283,11 +283,11 @@ namespace Ryujinx.Ava.Common
Dispatcher.UIThread.InvokeAsync(async () =>
{
await ContentDialogHelper.CreateInfoDialog(
- LocaleManager.Instance["DialogNcaExtractionSuccessMessage"],
+ LocaleManager.Instance[LocaleKeys.DialogNcaExtractionSuccessMessage],
"",
- LocaleManager.Instance["InputDialogOk"],
+ LocaleManager.Instance[LocaleKeys.InputDialogOk],
"",
- LocaleManager.Instance["DialogNcaExtractionTitle"]);
+ LocaleManager.Instance[LocaleKeys.DialogNcaExtractionTitle]);
});
}
}
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)