ASPNET Localization — Localizing Content and Views in .NET
DodaTech
Updated 2026-06-28
1 min read
In this tutorial, you'll learn about ASPNET Localization. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
Localization in ASP.NET Core adapts your application's UI, validation messages, and content to different cultures and languages.
// Shared resource class
public class SharedResources { }
// Usage with shared resources
public class ScanController : ControllerBase
{
private readonly IStringLocalizer<SharedResources> _sharedLocalizer;
public ScanController(IStringLocalizer<SharedResources> sharedLocalizer)
=> _sharedLocalizer = sharedLocalizer;
public IActionResult Status(int code)
{
var statusKey = $"ScanStatus_{code}";
var localized = _sharedLocalizer[statusKey];
return Ok(new { status = localized });
}
}
// Resources/Controllers.ScanController.fr-FR.resx
// Key: ScanCompleted, Value: Analyse terminee
// Key: ScanStatus_200, Value: Fichier propre - aucun danger detecte
// Data annotation localization
public class ScanRequest
{
[Required(ErrorMessageResourceName = "FileIdRequired", ErrorMessageResourceType = typeof(SharedResources))]
public string FileId { get; set; }
}
Proper localization separates UI text from code, enabling translators to work without modifying application logic.
← Previous
ASPNET Globalization — Internationalization in ASP.NET Core
Next →
ASPNET Background Tasks — Running Background Jobs in ASP.NET Core
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro