2023-01-03 13:45:08 -05:00
|
|
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
|
using System.Linq;
|
2023-10-05 06:41:00 -04:00
|
|
|
|
using System.Text;
|
2023-01-03 13:45:08 -05:00
|
|
|
|
|
|
|
|
|
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) =>
|
|
|
|
|
{
|
2023-07-01 02:29:37 -04:00
|
|
|
|
var lines = content.Split('\n').Where(x => x.Trim().StartsWith("\"")).Select(x => x.Split(':')[0].Trim().Replace("\"", ""));
|
2023-10-05 06:41:00 -04:00
|
|
|
|
StringBuilder enumSourceBuilder = new();
|
|
|
|
|
enumSourceBuilder.AppendLine("namespace Ryujinx.Ava.Common.Locale;");
|
|
|
|
|
enumSourceBuilder.AppendLine("internal enum LocaleKeys");
|
|
|
|
|
enumSourceBuilder.AppendLine("{");
|
2023-01-03 13:45:08 -05:00
|
|
|
|
foreach (var line in lines)
|
|
|
|
|
{
|
2023-10-05 06:41:00 -04:00
|
|
|
|
enumSourceBuilder.AppendLine($" {line},");
|
2023-01-03 13:45:08 -05:00
|
|
|
|
}
|
2023-10-05 06:41:00 -04:00
|
|
|
|
enumSourceBuilder.AppendLine("}");
|
2023-01-03 13:45:08 -05:00
|
|
|
|
|
2023-10-05 06:41:00 -04:00
|
|
|
|
spc.AddSource("LocaleKeys", enumSourceBuilder.ToString());
|
2023-01-03 13:45:08 -05:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|