PH.Babel2.Simple
1.0.0
dotnet add package PH.Babel2.Simple --version 1.0.0
NuGet\Install-Package PH.Babel2.Simple -Version 1.0.0
<PackageReference Include="PH.Babel2.Simple" Version="1.0.0" />
<PackageVersion Include="PH.Babel2.Simple" Version="1.0.0" />
<PackageReference Include="PH.Babel2.Simple" />
paket add PH.Babel2.Simple --version 1.0.0
#r "nuget: PH.Babel2.Simple, 1.0.0"
#:package PH.Babel2.Simple@1.0.0
#addin nuget:?package=PH.Babel2.Simple&version=1.0.0
#tool nuget:?package=PH.Babel2.Simple&version=1.0.0
PH.Babel2.Simple
PH.Babel2.Simple is a lightweight JSON-backed translation wrapper for applications that need direct string lookup without the full PH.Babel2 resource model.
Features
- Thread-safe in-memory translations with
ConcurrentDictionary - Lazy creation of missing keys and language entries
- Singleton-friendly registration through
AddBabelSimple - JSON persistence on
Dispose()
JSON format
{
"Hello": {
"en": "Hello",
"it": "Ciao"
},
"Welcome {0}": {
"en": "Welcome {0}",
"it": "Benvenuto {0}"
}
}
Direct usage
using PH.Babel2.Simple;
using var translator = new Translator("translations.json");
var italian = translator.Get("Hello", "it");
var welcome = translator.Get("Welcome {0}", "en", "John");
ASP.NET dependency injection
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddBabelSimple("translations.json");
Behavior notes
Note about key-as-fallback string
The key used to retrieve a message is also the fallback string — the text in the application's primary language. If a key is missing from the JSON file, the Translator automatically inserts it and uses the key text as the default translation for the primary language. This simplifies source usage: you can use the message text itself as the localization key (for example "Welcome {0}"), so if a translation for the requested culture is missing the original message will still be shown.
Examples
JSON (after a missing key is auto-added):
{
"Welcome {0}": {
"en": "Welcome {0}",
"it": "_"
}
}
C# usage:
using var translator = new Translator("translations.json");
// Key is the message itself; missing entries are handled automatically
var msgEn = translator.Get("Welcome {0}", "en", "John"); // "Welcome John"
var msgIt = translator.Get("Welcome {0}", "it", "Giovanni"); // formats fallback -> "Welcome Giovanni" if 'it' is '_'
- Missing keys are added automatically.
- Missing language values are stored with the
_placeholder. - When a value is
_, the original input text is formatted and returned.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- JetBrains.Annotations (>= 2018.2.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 124 | 6/24/2026 |