mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 12:38:24 +01:00
samples: add Hello/Demo samples for most BRUTAL packages
Add samples/, a collection of single-file .NET 10 apps run with `dotnet run <file>.cs`. Hello/ has one minimal sample per package that has a public API, many of them headless; Demo/ has fuller programs that combine packages into a more interesting application. samples/README.md indexes every sample and covers the layout, error handling and per-OS requirements.
This commit is contained in:
parent
a25cdf80b2
commit
b0c9fd9cdc
1 changed files with 4599 additions and 1 deletions
24
samples/Hello/HelloLocalization.cs
Normal file
24
samples/Hello/HelloLocalization.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* HelloLocalization
|
||||
*
|
||||
* Formats localised strings with named variables, then swaps in a French translation.
|
||||
*/
|
||||
|
||||
#:package Ahwoo.Brutal.Localization@2026.10.2
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Brutal.Localization;
|
||||
|
||||
var greeting = LStrings.Create("Greeting", "Hello {NAME}, you have {COUNT} new messages");
|
||||
|
||||
Console.WriteLine(greeting.Format("Alice", 3));
|
||||
|
||||
// A string provider supplies the localized text; replacement variables may be reordered.
|
||||
var french = new Dictionary<string, string> { ["Greeting"] = "{COUNT} nouveaux messages pour vous, {NAME}" };
|
||||
|
||||
bool FrenchProvider(LString lString, [NotNullWhen(true)] out string? text) =>
|
||||
french.TryGetValue(lString.Id.ToString(), out text);
|
||||
|
||||
LStrings.SetLocalizedStringProvider(FrenchProvider);
|
||||
|
||||
Console.WriteLine(greeting.Format("Alice", 3));
|
||||
Loading…
Reference in a new issue