You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Implement Marten multi-tenancy for localized projections by generating tenant-specific projection documents and removing the old localization helper.
Copy file name to clipboardExpand all lines: docs/localization-guide.md
+76-98Lines changed: 76 additions & 98 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,159 +4,137 @@ This guide explains how to configure and use localization in the BookStore API.
4
4
5
5
## Overview
6
6
7
-
The BookStore API supports multiple languages for localized content (category names, book descriptions, author biographies). The API automatically detects the client's preferred language from the `Accept-Language` HTTP header and returns localized content accordingly.
7
+
The BookStore API supports multiple languages for localized content (category names, book descriptions, author biographies).
8
+
9
+
**Architecture Strategy:**
10
+
The localization strategy uses **Write-Time Localization** via **Marten's Conjoined Tenancy**.
11
+
-**Events** contain all translations.
12
+
-**Projections** are multi-tenanted, with one document stored per supported language (tenant).
13
+
-**APIs** simply query the tenant corresponding to the user's preferred language.
14
+
15
+
This approach ensures high performance by eliminating complex runtime fallback logic during data retrieval.
8
16
9
17
## Configuration
10
18
11
-
### Two-Letter Language Codes
19
+
### Supported Languages
12
20
13
-
The API uses **two-letter ISO 639-1 language codes** for universal variant support:
21
+
The API is configured using **ISO 639-1 language codes**. You can configure either generic codes (e.g., `en`, `pt`) or specific regional cultures (e.g., `en-US`, `pt-BR`).
14
22
23
+
**Standard Configuration (Generic)**:
24
+
Suitable for applications where a single translation per language works for all regions.
Endpoints are simplified to purely read operations. They resolve the current culture (handled by ASP.NET Core middleware) and query the corresponding database tenant.
102
111
103
-
## Localized Endpoints
104
-
105
-
All public-facing endpoints return localized content:
-**ASP.NET Core Middleware**: `RequestLocalizationMiddleware` determines culture from `Accept-Language` header
115
-
-**LocalizationHelper**: Centralized helper with reusable methods:
116
-
-`GetLocalizedValue<T>()`: Generic method for translating any `Dictionary<string, T>`
117
-
-`LocalizeLanguageName()`: Gets localized display names for language codes
118
-
-`GetPreferredCulture()`: Retrieves user's preferred culture from middleware
119
-
-**Generic Translation Support**: Works with any translation type via selector functions
120
-
-**Null Safety**: Uses `[NotNullWhen(true)]` attribute for compile-time null safety
123
+
### Projection Implementation
121
124
122
-
### Usage Example
125
+
Projections are responsible for "fanning out" changes to all supported cultures. When an event (like `BookAdded`) occurs, the projection updates the documents for **all** configured tenants.
0 commit comments