Rystem.Localization 9.0.32

dotnet add package Rystem.Localization --version 9.0.32
                    
NuGet\Install-Package Rystem.Localization -Version 9.0.32
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rystem.Localization" Version="9.0.32" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rystem.Localization" Version="9.0.32" />
                    
Directory.Packages.props
<PackageReference Include="Rystem.Localization" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rystem.Localization --version 9.0.32
                    
#r "nuget: Rystem.Localization, 9.0.32"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Rystem.Localization&version=9.0.32
                    
Install Rystem.Localization as a Cake Addin
#tool nuget:?package=Rystem.Localization&version=9.0.32
                    
Install Rystem.Localization as a Cake Tool

What is Rystem?

Get Started with Localization and Rystem

Rystem Localization Library

Key Features

  • Integration-Friendly: Built specifically for integration with Repository Framework and CQRS (Query side).
  • Dynamic Content: Easily manage localization strings dynamically via repositories.
  • Extensible and Maintainable: Define your localization classes clearly and manage them with ease.

Getting Started

Step 1: Define Your Localization Classes

Create a strongly-typed dictionary for your localized strings:

public sealed class TheDictionary
{
    public string Value { get; set; }
    public TheFirstPage TheFirstPage { get; set; }
    public TheSecondPage TheSecondPage { get; set; }
}

public sealed class TheFirstPage
{
    public string Title { get; set; }
    public string Description { get; set; }
}

public sealed class TheSecondPage
{
    public FormattedString Title { get; set; }
}

Step 2: Register Localization with Repository Framework

In your Program.cs or Startup.cs, register localization:

services.AddLocalizationWithRepositoryFramework<TheDictionary>(builder =>
{
    builder.WithInMemory(name: "localization");
},
"localization",
async (serviceProvider) =>
{
    var repository = serviceProvider.GetRequiredService<IRepository<TheDictionary, string>>();
    await repository.InsertAsync("it", new TheDictionary
    {
        Value = "Valore",
        TheFirstPage = new TheFirstPage
        {
            Title = "Titolo",
            Description = "Descrizione"
        },
        TheSecondPage = new TheSecondPage
        {
            Title = "Titolo {0}"
        }
    });
    await repository.InsertAsync("en", new TheDictionary
    {
        Value = "Value",
        TheFirstPage = new TheFirstPage
        {
            Title = "Title",
            Description = "Description"
        },
        TheSecondPage = new TheSecondPage
        {
            Title = "Title {0}"
        }
    });
});

Step 3: Usage in Blazor Components

Use localization in your Blazor components easily:

@inject IRystemLocalizer<TheDictionary> Localizer

<h2>@Localizer.Instance.Value</h2>
<h3>@Localizer.Instance.TheFirstPage.Title</h3>
<p>@Localizer.Instance.TheFirstPage.Description</p>
<p>@Localizer.Instance.TheSecondPage.Title["Your parameter"]</p>

Step 4: Browser Language Detection in Blazor

Automatically set the culture based on browser language. Use Routes.razor as follows:

@using Microsoft.AspNetCore.WebUtilities

@code {
    private Userone? user;
    private string userId = "1";

    protected override async Task OnInitializedAsync()
    {
        var uri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
        if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("userId", out var userIdValue))
        {
            userId = userId.FirstOrDefault();
        }

        var repository = serviceProvider.GetRequiredService<IRepository<Userone, string>>();
        user = await repository.GetAsync(userId);

        if (user?.Language != null)
        {
            var culture = new CultureInfo(user.Language);
            CultureInfo.DefaultThreadCurrentCulture = culture;
            CultureInfo.DefaultThreadCurrentCulture = culture;
            CultureInfo.DefaultThreadCurrentCulture = culture;
            CultureInfo.DefaultThreadCurrentUICulture = culture;
        }
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (user?.Language == null)
        {
            var browserLanguage = "en"; // obtain actual browser language here
            user.Language = browserLanguage;
            await repository.UpdateAsync(userId, user);
            NavigationManager.Refresh();
        }
    }
}

How It Works

  • Initialization: Localization resources are loaded into repositories at startup.
  • Retrieval: Strings retrieved based on the user's current culture.
  • Fallback: Defaults to English if a localization string is missing.

Why Use This Library?

  • Scalable: Central repository simplifies localization management.
  • Maintainable: Easy updates to localization without redeployment.
  • Consistent: Strongly-typed localization for error reduction.

Example with CQRS Framework

services.AddLocalizationWithRepositoryFramework<TheDictionary>(builder =>
{
    builder.WithInMemory(name: "localization");
}, "localization");

Error Handling

An exception is thrown during startup if no languages are configured:

Exception: No languages found

Ensure at least one localization entry is provided.


© 2024 Rystem Localization. All Rights Reserved.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
9.0.32 55,509 9 days ago
9.0.31 5,726 23 days ago
9.0.30 88,763 a month ago
9.0.29 8,914 a month ago
9.0.28 133 a month ago
9.0.27 134 a month ago
9.0.26 131 a month ago