mirror of
https://github.com/GreemDev/Ryujinx
synced 2024-11-23 02:06:55 +01:00
02714a1291
* Add source generator for locale keys * use locale keys in Ui subdir
30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
using Microsoft.CodeAnalysis;
|
|
using System.Linq;
|
|
|
|
namespace Ryujinx.Ui.LocaleGenerator
|
|
{
|
|
[Generator]
|
|
public class LocaleGenerator : IIncrementalGenerator
|
|
{
|
|
public void Initialize(IncrementalGeneratorInitializationContext context)
|
|
{
|
|
var englishLocaleFile = context.AdditionalTextsProvider.Where(static x => x.Path.EndsWith("en_US.json"));
|
|
|
|
IncrementalValuesProvider<string> contents = englishLocaleFile.Select((text, cancellationToken) => text.GetText(cancellationToken)!.ToString());
|
|
|
|
context.RegisterSourceOutput(contents, (spc, content) =>
|
|
{
|
|
var lines = content.Split('\n').Where(x => x.Trim().StartsWith("\"")).Select(x => x.Split(':').First().Trim().Replace("\"", ""));
|
|
string enumSource = "namespace Ryujinx.Ava.Common.Locale;\n";
|
|
enumSource += "internal enum LocaleKeys\n{\n";
|
|
foreach (var line in lines)
|
|
{
|
|
enumSource += $" {line},\n";
|
|
}
|
|
enumSource += "}\n";
|
|
|
|
spc.AddSource("LocaleKeys", enumSource);
|
|
});
|
|
}
|
|
}
|
|
}
|