mirror of
https://github.com/GreemDev/Ryujinx
synced 2024-12-22 11:56:36 +01:00
Compare commits
5 commits
497bb7fef8
...
1a7b3bf874
Author | SHA1 | Date | |
---|---|---|---|
|
1a7b3bf874 | ||
|
fd87c6f6ed | ||
|
7843195733 | ||
|
22895bf520 | ||
|
95fedf4a78 |
4 changed files with 296 additions and 240 deletions
File diff suppressed because it is too large
Load diff
|
@ -1,12 +1,18 @@
|
|||
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
|
||||
{
|
||||
|
@ -144,7 +150,9 @@ 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/locales.json");
|
||||
string fileData = EmbeddedResources.ReadAllText($"Ryujinx/Assets/locales.json");
|
||||
|
||||
bool invalidLocalesJson = false; //does the locales.json contain all the languages in all the locales?
|
||||
|
||||
if (fileData == null)
|
||||
{
|
||||
|
@ -152,14 +160,19 @@ namespace Ryujinx.Ava.Common.Locale
|
|||
return null;
|
||||
}
|
||||
|
||||
LocalesJSON json = JsonSerializer.Deserialize<LocalesJSON>(fileData)!;
|
||||
LocalesJSON json = JsonHelper.Deserialize(fileData, LocalesJSONContext.Default.LocalesJSON);
|
||||
|
||||
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))
|
||||
|
@ -176,6 +189,45 @@ 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;
|
||||
}
|
||||
}
|
||||
|
@ -191,4 +243,8 @@ 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 { }
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\Locales\locales.json" />
|
||||
<None Remove="Assets\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\locales.json" />
|
||||
<EmbeddedResource Include="Assets\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\locales.json" />
|
||||
<AdditionalFiles Include="Assets\locales.json" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -10,6 +10,7 @@ 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;
|
||||
|
@ -18,7 +19,6 @@ 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/locales.json";
|
||||
string localePath = "Ryujinx/Assets/locales.json";
|
||||
|
||||
string languageJson = EmbeddedResources.ReadAllText(localePath);
|
||||
|
||||
LocalesJSON locales = JsonSerializer.Deserialize<LocalesJSON>(languageJson);
|
||||
LocalesJSON locales = JsonHelper.Deserialize(languageJson, LocalesJSONContext.Default.LocalesJSON);
|
||||
|
||||
foreach (string language in locales.Languages)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue