0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2025-01-10 08:11:59 +00:00
Ryujinx/src/Ryujinx.UI.LocaleGenerator/LocaleGenerator.cs
LotP1 9cddf3b66b
Unified locales (#391)
Use 1 locales file instead of individual files for each langauge.
This makes it easier to keep track of what is missing.
The PR will automatically fix missing locales and throw an error if
anything is incorrect, by running the emulator. That way the person
adding a new locale or new language can just run the emulator once to
populate all the fields, so they can easily begin translating.
2024-12-20 13:27:11 -06:00

34 lines
1.4 KiB
C#

using Microsoft.CodeAnalysis;
using System.Linq;
using System.Text;
namespace Ryujinx.UI.LocaleGenerator
{
[Generator]
public class LocaleGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var localeFile = context.AdditionalTextsProvider.Where(static x => x.Path.EndsWith("locales.json"));
IncrementalValuesProvider<string> contents = localeFile.Select((text, cancellationToken) => text.GetText(cancellationToken)!.ToString());
context.RegisterSourceOutput(contents, (spc, content) =>
{
var lines = content.Split('\n').Where(x => x.Trim().StartsWith("\"ID\":")).Select(x => x.Split(':')[1].Trim().Replace("\"", string.Empty).Replace(",", string.Empty));
StringBuilder enumSourceBuilder = new();
enumSourceBuilder.AppendLine("namespace Ryujinx.Ava.Common.Locale;");
enumSourceBuilder.AppendLine("internal enum LocaleKeys");
enumSourceBuilder.AppendLine("{");
foreach (var line in lines)
{
enumSourceBuilder.AppendLine($" {line},");
}
enumSourceBuilder.AppendLine("}");
spc.AddSource("LocaleKeys", enumSourceBuilder.ToString());
});
}
}
}