Avalonia - Add source generator for locale items (#3999)
* Add source generator for locale keys * use locale keys in Ui subdir
This commit is contained in:
parent
09c9686498
commit
02714a1291
40 changed files with 337 additions and 271 deletions
30
Ryujinx.Ui.LocaleGenerator/LocaleGenerator.cs
Normal file
30
Ryujinx.Ui.LocaleGenerator/LocaleGenerator.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
20
Ryujinx.Ui.LocaleGenerator/Ryujinx.Ui.LocaleGenerator.csproj
Normal file
20
Ryujinx.Ui.LocaleGenerator/Ryujinx.Ui.LocaleGenerator.csproj
Normal file
|
@ -0,0 +1,20 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
||||
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
|
||||
<IsRoslynComponent>true</IsRoslynComponent>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue