Compare commits

..

No commits in common. "1a7b3bf874e1a6aa04ee43d83d7baddabaffc3c6" and "497bb7fef8374fee33d84e3defaf921a644d1aa5" have entirely different histories.

4 changed files with 240 additions and 296 deletions

View file

@ -1,18 +1,12 @@
using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Common.Utilities;
using Ryujinx.UI.Common.Configuration;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Unicode;
namespace Ryujinx.Ava.Common.Locale
{
@ -150,9 +144,7 @@ namespace Ryujinx.Ava.Common.Locale
private static Dictionary<LocaleKeys, string> LoadJsonLanguage(string languageCode)
{
var localeStrings = new Dictionary<LocaleKeys, string>();
string fileData = EmbeddedResources.ReadAllText($"Ryujinx/Assets/locales.json");
bool invalidLocalesJson = false; //does the locales.json contain all the languages in all the locales?
string fileData = EmbeddedResources.ReadAllText($"Ryujinx/Assets/Locales/locales.json");
if (fileData == null)
{
@ -160,19 +152,14 @@ namespace Ryujinx.Ava.Common.Locale
return null;
}
LocalesJSON json = JsonHelper.Deserialize(fileData, LocalesJSONContext.Default.LocalesJSON);
LocalesJSON json = JsonSerializer.Deserialize<LocalesJSON>(fileData)!;
foreach (LocalesEntry locale in json.Locales)
{
if (locale.Translations.Count != json.Languages.Count)
{
Logger.Error?.Print(LogClass.UI, $"Locale key {{{locale.ID}}} is missing languages!");
invalidLocalesJson = true;
#if DEBUG
break;
#else
throw new Exception("Missing locale data!");
#endif
}
if (Enum.TryParse<LocaleKeys>(locale.ID, out var localeKey))
@ -189,45 +176,6 @@ namespace Ryujinx.Ava.Common.Locale
}
}
if (invalidLocalesJson)
{
for (int i = 0; i < json.Locales.Count; i++)
{
LocalesEntry locale = json.Locales[i];
foreach (string language in json.Languages)
{
if (!locale.Translations.ContainsKey(language))
{
locale.Translations.Add(language, "");
Logger.Warning?.Print(LogClass.UI, $"Added {{{language}}} to Locale {{{locale.ID}}}");
}
}
locale.Translations = locale.Translations.OrderBy(pair => pair.Key).ToDictionary(pair => pair.Key, pair => pair.Value);
json.Locales[i] = locale;
}
string location = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.GetDirectories("Assets")[0].GetFiles("locales.json")[0].FullName;
JsonSerializerOptions jsonOptions = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
};
LocalesJSONContext context = new LocalesJSONContext(jsonOptions);
string jsonString = JsonHelper.Serialize(json, context.LocalesJSON);
using (StreamWriter sw = new StreamWriter(location))
{
sw.Write(jsonString);
}
throw new Exception("Missing locale data! (missing locale data has been added, please rebuild the project)");
}
return localeStrings;
}
}
@ -243,8 +191,4 @@ namespace Ryujinx.Ava.Common.Locale
public string ID { get; set; }
public Dictionary<string, string> Translations { get; set; }
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(LocalesJSON))]
internal partial class LocalesJSONContext : JsonSerializerContext { }
}

View file

@ -112,7 +112,7 @@
</ItemGroup>
<ItemGroup>
<None Remove="Assets\locales.json" />
<None Remove="Assets\Locales\locales.json" />
<None Remove="Assets\Styles\Styles.xaml" />
<None Remove="Assets\Styles\Themes.xaml" />
<None Remove="Assets\Icons\Controller_JoyConLeft.svg" />
@ -122,7 +122,7 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Assets\locales.json" />
<EmbeddedResource Include="Assets\Locales\locales.json" />
<EmbeddedResource Include="Assets\Styles\Styles.xaml" />
<EmbeddedResource Include="Assets\Icons\Controller_JoyConLeft.svg" />
<EmbeddedResource Include="Assets\Icons\Controller_JoyConPair.svg" />
@ -130,6 +130,6 @@
<EmbeddedResource Include="Assets\Icons\Controller_ProCon.svg" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="Assets\locales.json" />
<AdditionalFiles Include="Assets\Locales\locales.json" />
</ItemGroup>
</Project>

View file

@ -10,7 +10,6 @@ using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Ava.UI.Windows;
using Ryujinx.Common;
using Ryujinx.Common.Utilities;
using Ryujinx.HLE;
using Ryujinx.UI.App.Common;
using Ryujinx.UI.Common;
@ -19,6 +18,7 @@ using Ryujinx.UI.Common.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
namespace Ryujinx.Ava.UI.Views.Main
{
@ -53,11 +53,11 @@ namespace Ryujinx.Ava.UI.Views.Main
{
List<MenuItem> menuItems = new();
string localePath = "Ryujinx/Assets/locales.json";
string localePath = "Ryujinx/Assets/Locales/locales.json";
string languageJson = EmbeddedResources.ReadAllText(localePath);
LocalesJSON locales = JsonHelper.Deserialize(languageJson, LocalesJSONContext.Default.LocalesJSON);
LocalesJSON locales = JsonSerializer.Deserialize<LocalesJSON>(languageJson);
foreach (string language in locales.Languages)
{