Compare commits

...

2 Commits

Author SHA1 Message Date
dependabot[bot]
d26ef2eec3 nuget: bump Microsoft.CodeAnalysis.CSharp from 4.8.0 to 4.9.2 (#6397)
Bumps [Microsoft.CodeAnalysis.CSharp](https://github.com/dotnet/roslyn) from 4.8.0 to 4.9.2.
- [Release notes](https://github.com/dotnet/roslyn/releases)
- [Changelog](https://github.com/dotnet/roslyn/blob/main/docs/Breaking%20API%20Changes.md)
- [Commits](https://github.com/dotnet/roslyn/commits)

---
updated-dependencies:
- dependency-name: Microsoft.CodeAnalysis.CSharp
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-17 02:55:11 +01:00
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
2 changed files with 34 additions and 22 deletions

View File

@@ -19,7 +19,7 @@
<PackageVersion Include="GtkSharp.Dependencies.osx" Version="0.0.5" /> <PackageVersion Include="GtkSharp.Dependencies.osx" Version="0.0.5" />
<PackageVersion Include="LibHac" Version="0.19.0" /> <PackageVersion Include="LibHac" Version="0.19.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" /> <PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" /> <PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.4.0" /> <PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.4.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" /> <PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />

View File

@@ -30,28 +30,22 @@ namespace Ryujinx.Ava.Common.Locale
Load(); Load();
} }
public void Load() private void Load()
{ {
// Load the system Language Code. var localeLanguageCode = !string.IsNullOrEmpty(ConfigurationState.Instance.UI.LanguageCode.Value) ?
string localeLanguageCode = CultureInfo.CurrentCulture.Name.Replace('-', '_'); 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 (Program.PreviewerDetached)
{ {
if (!string.IsNullOrEmpty(ConfigurationState.Instance.UI.LanguageCode.Value)) ConfigurationState.Instance.UI.LanguageCode.Value = _localeLanguageCode;
{
localeLanguageCode = ConfigurationState.Instance.UI.LanguageCode.Value;
}
else
{
localeLanguageCode = DefaultLanguageCode;
}
}
// Load en_US as default, if the target language translation is incomplete. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
LoadDefaultLanguage(); }
LoadLanguage(localeLanguageCode);
} }
public string this[LocaleKeys key] public string this[LocaleKeys key]
@@ -126,24 +120,42 @@ namespace Ryujinx.Ava.Common.Locale
private void LoadDefaultLanguage() private void LoadDefaultLanguage()
{ {
_localeDefaultStrings = LoadJsonLanguage(); _localeDefaultStrings = LoadJsonLanguage(DefaultLanguageCode);
} }
public void LoadLanguage(string languageCode) 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; this[item.Key] = item.Value;
} }
_localeLanguageCode = languageCode;
LocaleChanged?.Invoke(); 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>(); var localeStrings = new Dictionary<LocaleKeys, string>();
string languageJson = EmbeddedResources.ReadAllText($"Ryujinx/Assets/Locales/{languageCode}.json"); 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); var strings = JsonHelper.Deserialize(languageJson, CommonJsonContext.Default.StringDictionary);
foreach (var item in strings) foreach (var item in strings)