diff --git a/docs/external_integrations/push_notifications_fcm/index.md b/docs/external_integrations/push_notifications_fcm/index.md index b913bcebb..af4eba6fa 100644 --- a/docs/external_integrations/push_notifications_fcm/index.md +++ b/docs/external_integrations/push_notifications_fcm/index.md @@ -51,7 +51,7 @@ public override void ConfigureServices(IServiceCollection services) } ``` -> **Tip:** Further details about localization can be found here. +> **Tip:** Further details about localization can be found [here](../../features/localization/index.md). Following the above configuration, it is necessary to incorporate a `DbSet` for the push notification token store. This can be accomplished through `CoreDbContext`, utilizing `Microsoft.EntityFrameworkCore`. diff --git a/docs/features/localization/index.md b/docs/features/localization/index.md new file mode 100644 index 000000000..4691b1a03 --- /dev/null +++ b/docs/features/localization/index.md @@ -0,0 +1,93 @@ +# Localization + +Effectively handling localization is crucial in ensuring software compatibility across diverse linguistic and cultural contexts. The `LeanCode.Localization` package, integrated within the CoreLibrary, provides a solution for managing language-specific content. This integration simplifies the configuration and customization of localization, facilitating the localization of [emails] and [push notifications] with ease. + +## Packages + +| Package | Link | Application in section | +| --- | ----------- | ----------- | +| LeanCode.Localization | [![NuGet version (LeanCode.Localization)](https://img.shields.io/nuget/vpre/LeanCode.Localization.svg?style=flat-square)](https://www.nuget.org/packages/LeanCode.Localization/8.0.2260-preview/) | Localization | + +## Configuration + +To begin, let's introduce the `Strings.cs` marker class: + +```csharp +public class Strings { } +``` + +Subsequently, we create the `Strings.resx` which serves as the default localization file, and should be placed in the same directory as the `Strings.cs` marker class: + +```xml + + + + Meeting {0} has started. + + +``` + +For German-specific strings, we define the `Strings.de.resx` file: + +```xml + + + + Besprechung {0} hat begonnen. + + +``` + +To register the localizer, simply follow the configuration outlined below: + +```csharp +public override void ConfigureServices(IServiceCollection services) +{ + // . . . + + services.AddStringLocalizer( + LocalizationConfiguration.For()); + + // . . . +} +``` + +Configuration above enables us to send localized and parameterized [push notifications], [emails] and extract language specific strings using `IStringLocalizer` interface: + +```csharp +public class Example +{ + private readonly IStringLocalizer localizer; + + public Example(IStringLocalizer localizer) + { + this.localizer = localizer; + } + + public void Method() + { + var key = "meeting-started"; + + var defaultValue = localizer[CultureInfo.InvariantCulture, key]; + + // Meeting {0} has started. + Console.WriteLine(defaultValue); + + var localizedValue = localizer[new CultureInfo("de-DE"), key]; + + // Besprechung {0} hat begonnen. + Console.WriteLine(localizedValue); + + var localizedParameterizedValue = localizer.Format( + new CultureInfo("de-DE"), + key, + "Name der Besprechung"); + + // Besprechung Name der Besprechung hat begonnen. + Console.WriteLine(localizedParameterizedValue); + } +} +``` + +[push notifications]: ../../external_integrations/push_notifications_fcm/index.md +[emails]: ../../external_integrations/emails_sendgrid/index.md diff --git a/mkdocs.yml b/mkdocs.yml index 8d350ec5f..a0d6c7354 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -68,6 +68,8 @@ nav: - ./features/audit_logs/index.md - Force update: - ./features/force_update/index.md + - Localization: + - ./features/localization/index.md - Tests: - Integration tests: - ./tests/integration_tests/index.md