Lesson 30 of 40 Web Development Intermediate 35 min

Globalization & Localization

Build world-ready applications with proper localization, resource files, culture-aware formatting, and RTL language support.

Part 1: Resource File Localization

// Resources/Messages.resx (default)
// Resources/Messages.ar.resx (Arabic)
// Resources/Messages.fr.resx (French)

builder.Services.AddLocalization(o => o.ResourcesPath = "Resources");

// Inject IStringLocalizer<T>
_localizer["WelcomeMessage"]

Part 2: Request Localization Middleware

app.UseRequestLocalization(new RequestLocalizationOptions
{
  SupportedCultures = ["en", "fr", "ar", "zh"],
  SupportedUICultures = ["en", "fr", "ar", "zh"],
  DefaultRequestCulture = new("en")
});

Part 3: Culture-Aware Formatting

// Always pass culture explicitly in libraries
var price = (1234.56m).ToString("C", new CultureInfo("de-DE"));
// Result: 1.234,56 โ‚ฌ

var date = DateTime.Now.ToString("D", new CultureInfo("ja-JP"));
// Result: 2026ๅนด3ๆœˆ11ๆ—ฅ

Part 4: RTL Support in Blazor/Razor

<!-- Set direction based on culture -->
<html lang="@CultureInfo.CurrentUICulture.Name"
      dir="@(IsRtl ? "rtl" : "ltr")">

@code {
  bool IsRtl => CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft;
}
VISUAL STUDIO 2026 MADE EASY
Recommended Book

VISUAL STUDIO 2026 MADE EASY

Build real applications with C#, VB.NET, Python, JavaScript, C++, and .NET 10. A practical companion for mastering Visual Studio 2026 step by step.