Skip to content

Localization Registry

The ILocalizationRegistry stores mappings from type full names to localized template strings, organized by culture.

JSON Registry

The JsonLocalizationRegistry loads templates from JSON files. Templates are typically stored as embedded resources in your assembly.

JSON Format

Each JSON file contains a flat dictionary mapping type full names to format strings:

{
"MyApp.Errors.RequiredFieldError": "'{FieldName}' is required",
"MyApp.Errors.InvalidEmailError": "'{Email}' is not a valid email address"
}

File Naming Convention

JSON files follow the pattern localized-messages.{culture}.json:

  • localized-messages.en-US.json — English (US)
  • localized-messages.it-IT.json — Italian
  • localized-messages.json — Invariant culture (fallback)

Loading from Embedded Resources

Mark your JSON files as embedded resources in your .csproj:

<ItemGroup>
<EmbeddedResource Include="localized-messages.en-US.json" WithCulture="false" />
<EmbeddedResource Include="localized-messages.it-IT.json" WithCulture="false" />
</ItemGroup>

Then register the assembly containing the resources:

services.AddLocalization(typeof(MyType).Assembly);

In-Memory Registry

The InMemoryLocalizationRegistry is a simple dictionary-backed registry, useful for testing:

var registry = new InMemoryLocalizationRegistryBuilder()
.AddTemplate("en-US", "MyApp.Errors.RequiredFieldError", "'{FieldName}' is required")
.AddTemplate("it-IT", "MyApp.Errors.RequiredFieldError", "'{FieldName}' è obbligatorio")
.Build();