diff options
| author | TSR Berry <20988865+TSRBerry@users.noreply.github.com> | 2023-04-08 01:22:00 +0200 |
|---|---|---|
| committer | Mary <thog@protonmail.com> | 2023-04-27 23:51:14 +0200 |
| commit | cee712105850ac3385cd0091a923438167433f9f (patch) | |
| tree | 4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /src/Ryujinx.Ui.LocaleGenerator | |
| parent | cd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff) | |
Move solution and projects to src
Diffstat (limited to 'src/Ryujinx.Ui.LocaleGenerator')
| -rw-r--r-- | src/Ryujinx.Ui.LocaleGenerator/LocaleGenerator.cs | 30 | ||||
| -rw-r--r-- | src/Ryujinx.Ui.LocaleGenerator/Ryujinx.Ui.LocaleGenerator.csproj | 18 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/Ryujinx.Ui.LocaleGenerator/LocaleGenerator.cs b/src/Ryujinx.Ui.LocaleGenerator/LocaleGenerator.cs new file mode 100644 index 00000000..f154e704 --- /dev/null +++ b/src/Ryujinx.Ui.LocaleGenerator/LocaleGenerator.cs @@ -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); + }); + } + } +} diff --git a/src/Ryujinx.Ui.LocaleGenerator/Ryujinx.Ui.LocaleGenerator.csproj b/src/Ryujinx.Ui.LocaleGenerator/Ryujinx.Ui.LocaleGenerator.csproj new file mode 100644 index 00000000..05cbc764 --- /dev/null +++ b/src/Ryujinx.Ui.LocaleGenerator/Ryujinx.Ui.LocaleGenerator.csproj @@ -0,0 +1,18 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>netstandard2.0</TargetFramework> + <Nullable>enable</Nullable> + <LangVersion>latest</LangVersion> + <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> + </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> |
