Haren (Ems)
sh-edraft.core.translation (2026.9.9.3)
Published 2026-09-09 17:23:53 +02:00 by ci
Installation
dotnet nuget add source --name sh-edraft.de --username your_username --password your_token https://git.sh-edraft.de/api/packages/sh-edraft.de/nuget/index.jsondotnet add package --source sh-edraft.de --version 2026.9.9.3 sh-edraft.core.translationAbout this package
JSON file translations
sh-edraft Core Translation
JSON file-based translation service with variable interpolation and multi-language support.
Features
- JSON-based translation files
- Variable interpolation in translation strings
- Multi-language support with configurable default language
- Automatic fallback to default language when a key is missing
- Thread-safe in-memory cache
Installation
Install via NuGet:
dotnet add package sh-edraft.core.translation
Configuration
Configure via appsettings.json or environment variables:
| Key | Default | Description |
|---|---|---|
LANGUAGES |
(none) | Comma-separated list of supported language codes (e.g. en,de,fr) |
DEFAULT_LANGUAGE |
en |
Fallback language when a key is not found in the requested language |
TRANSLATION_PATH |
translations/{language}.json |
Path template for translation files; {language} is replaced with the language code |
Usage
Register services
builder.Services.AddTranslation();
Load translations on startup
app.UseTranslation();
This calls LoadLanguages() which loads all languages defined in LANGUAGES.
Translate
public class MyService(ITranslationService translation)
{
public string Greet(string name)
=> translation.Translate("greeting", new Dictionary<string, string> { ["name"] = name });
}
Translation file example (translations/en.json)
{
"greeting": "Hello, {name}!",
"farewell": "Goodbye!"
}
Variables in translation strings are written as {variableName} and replaced at runtime via the variables dictionary.
License
MIT
Dependencies
Details
Assets (4)
Versions (38)
View all
sh.core.translation.pdb
13 KiB
2026.9.10.2
2026-09-10
2026.9.10.1
2026-09-10
2026.9.10
2026-09-10
2026.9.9.3
2026-09-09
2026.9.9.2
2026-09-09