Compare commits

..

2 Commits

Author SHA1 Message Date
Isaac Marovitz
a0552fd78b Ava UI: Fix locale crash (#6385)
* Fix locale crash

* Apply suggestions from code review

---------

Co-authored-by: Ac_K <Acoustik666@gmail.com>
2024-03-17 02:27:14 +01:00
Isaac Marovitz
bb8c5ebae1 Ava UI: Content Dialog Fixes (#6482)
* Don’t use ContentDialogHelper when not necessary

* Remove `ExtendClientAreaToDecorationsHint`
2024-03-16 20:34:26 +01:00
4 changed files with 35 additions and 24 deletions

View File

@@ -30,28 +30,22 @@ namespace Ryujinx.Ava.Common.Locale
Load();
}
public void Load()
private void Load()
{
// Load the system Language Code.
string localeLanguageCode = CultureInfo.CurrentCulture.Name.Replace('-', '_');
var localeLanguageCode = !string.IsNullOrEmpty(ConfigurationState.Instance.UI.LanguageCode.Value) ?
ConfigurationState.Instance.UI.LanguageCode.Value : CultureInfo.CurrentCulture.Name.Replace('-', '_');
// If the view is loaded with the UI Previewer detached, then override it with the saved one or default.
// Load en_US as default, if the target language translation is missing or incomplete.
LoadDefaultLanguage();
LoadLanguage(localeLanguageCode);
// Save whatever we ended up with.
if (Program.PreviewerDetached)
{
if (!string.IsNullOrEmpty(ConfigurationState.Instance.UI.LanguageCode.Value))
{
localeLanguageCode = ConfigurationState.Instance.UI.LanguageCode.Value;
}
else
{
localeLanguageCode = DefaultLanguageCode;
}
ConfigurationState.Instance.UI.LanguageCode.Value = _localeLanguageCode;
ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
}
// Load en_US as default, if the target language translation is incomplete.
LoadDefaultLanguage();
LoadLanguage(localeLanguageCode);
}
public string this[LocaleKeys key]
@@ -126,24 +120,42 @@ namespace Ryujinx.Ava.Common.Locale
private void LoadDefaultLanguage()
{
_localeDefaultStrings = LoadJsonLanguage();
_localeDefaultStrings = LoadJsonLanguage(DefaultLanguageCode);
}
public void LoadLanguage(string languageCode)
{
foreach (var item in LoadJsonLanguage(languageCode))
var locale = LoadJsonLanguage(languageCode);
if (locale == null)
{
_localeLanguageCode = DefaultLanguageCode;
locale = _localeDefaultStrings;
}
else
{
_localeLanguageCode = languageCode;
}
foreach (var item in locale)
{
this[item.Key] = item.Value;
}
_localeLanguageCode = languageCode;
LocaleChanged?.Invoke();
}
private static Dictionary<LocaleKeys, string> LoadJsonLanguage(string languageCode = DefaultLanguageCode)
private static Dictionary<LocaleKeys, string> LoadJsonLanguage(string languageCode)
{
var localeStrings = new Dictionary<LocaleKeys, string>();
string languageJson = EmbeddedResources.ReadAllText($"Ryujinx/Assets/Locales/{languageCode}.json");
if (languageJson == null)
{
// We were unable to find file for that language code.
return null;
}
var strings = JsonHelper.Deserialize(languageJson, CommonJsonContext.Default.StringDictionary);
foreach (var item in strings)

View File

@@ -9,7 +9,6 @@ namespace Ryujinx.Ava.UI.Windows
{
InitializeComponent();
ExtendClientAreaToDecorationsHint = true;
TransparencyLevelHint = new[] { WindowTransparencyLevel.Transparent };
WindowStartupLocation = WindowStartupLocation.Manual;
SystemDecorations = SystemDecorations.None;

View File

@@ -47,7 +47,7 @@ namespace Ryujinx.Ava.UI.Windows
contentDialog.Styles.Add(bottomBorder);
await ContentDialogHelper.ShowAsync(contentDialog);
await contentDialog.ShowAsync();
}
private void SaveAndClose(object sender, RoutedEventArgs routedEventArgs)

View File

@@ -49,7 +49,7 @@ namespace Ryujinx.Ava.UI.Windows
contentDialog.Styles.Add(bottomBorder);
await ContentDialogHelper.ShowAsync(contentDialog);
await contentDialog.ShowAsync();
}
private void Close(object sender, RoutedEventArgs e)