RSCG – LingoGen
name | LingoGen |
nuget | https://www.nuget.org/packages/RubenBroere.LingoGen/ |
link | https://github.com/RubenBroere/lingo-gen |
author | Ruben Broere |
Translating from multiple languages
This is how you can use LingoGen .
The code that you start with is
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | < Project Sdk = "Microsoft.NET.Sdk" > < PropertyGroup > < OutputType >Exe</ OutputType > < TargetFramework >net8.0</ TargetFramework > < ImplicitUsings >enable</ ImplicitUsings > < Nullable >enable</ Nullable > </ PropertyGroup > < ItemGroup > < None Remove = "lingo.json" /> </ ItemGroup > < ItemGroup > < AdditionalFiles Include = "lingo.json" /> </ ItemGroup > < ItemGroup > < PackageReference Include = "RubenBroere.LingoGen" Version = "0.2.1" OutputItemType = "Analyzer" ReferenceOutputAssembly = "false" /> </ ItemGroup > < PropertyGroup > < EmitCompilerGeneratedFiles >true</ EmitCompilerGeneratedFiles > < CompilerGeneratedFilesOutputPath >$(BaseIntermediateOutputPath)\GX</ CompilerGeneratedFilesOutputPath > </ PropertyGroup > </ Project > |
The code that you will use is
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 | using System.Globalization; var name = "Andrei " ; CultureInfo newCulture = new CultureInfo( "en" ); Thread.CurrentThread.CurrentUICulture = newCulture; Console.WriteLine(LingoGen.Lingo.Hello_(name)); newCulture = new CultureInfo( "fr" ); Thread.CurrentThread.CurrentUICulture = newCulture; Console.WriteLine(LingoGen.Lingo.Hello_(name)); newCulture = new CultureInfo( "it" ); Thread.CurrentThread.CurrentUICulture = newCulture; Console.WriteLine(LingoGen.Lingo.Hello_(name)); |
The code that is generated is
01 02 03 04 05 06 07 08 09 10 11 12 | // <auto-generated/> namespace LingoGen; /// <summary> /// Static class containing all lingo entries. /// </summary> public static partial class Lingo { } |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 | // <auto-generated/> using System; using System.Globalization; namespace LingoGen; public static partial class Lingo { /// <summary> /// Hello {Name} /// </summary> public static string Hello_( string Name) => CultureInfo.CurrentUICulture.TwoLetterISOLanguageName switch { "it" => $ "Buongiorno {Name}" , "fr" => $ "Bonjour {Name}" , "en" => $ "Hello {Name}" , _ => $ "[ No 'Hello_' lingo for '{CultureInfo.CurrentUICulture.TwoLetterISOLanguageName}' ]" }; } |
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/LingoGen
Leave a Reply