ASP.NET Core  

Globalization and Localization in ASP.NET Core

Modern applications are used by people from different countries, cultures, and languages.
ASP.NET Core provides built-in support for making your application culture- and language-aware.

What is Globalization?

Globalization is the process of designing an application to support multiple cultures.

It deals with:

  • Date & time formats

  • Number formats

  • Currency

  • Culture-specific rules

Example:

  • US Date → 12/31/2026

  • India Date → 31/12/2026

  • Currency → $100 vs ₹100

What is Localization?

Localization means adapting the application to a specific language or region.

It focuses on:

  • Translated text

  • Culture-specific resources

  • Language selection

Example:

  • English → “Welcome”

  • French → “Bienvenue”

  • Spanish → “Bienvenido”

Difference Between Globalization and Localization

FeatureGlobalizationLocalization
PurposeCulture supportLanguage support
ScopeFormats & rulesText & UI
ExampleDate, currencyMessages, labels

Real-World Scenario

An e-commerce website supports:

  • English (US)

  • French (France)

  • Arabic (Saudi Arabia)

Users see:

  • Product prices in correct currency

  • Dates in local format

  • UI text in their language

Culture and Language in ASP.NET Core

ASP.NET Core uses:

  • Culture → formatting (en-US, fr-FR)

  • UICulture → UI language

Example culture codes:

  • en-US → English (United States)

  • fr-FR → French (France)

  • ar-SA → Arabic (Saudi Arabia)

Enable Localization in ASP.NET Core

Step 1: Add Localization Services

builder.Services.AddLocalization(options =>
{
    options.ResourcesPath = "Resources";
});

Step 2: Configure Supported Cultures

using Microsoft.AspNetCore.Localization;
using System.Globalization;

var supportedCultures = new[]
{
    new CultureInfo("en-US"),
    new CultureInfo("fr-FR"),
    new CultureInfo("ar-SA")
};

var localizationOptions = new RequestLocalizationOptions
{
    DefaultRequestCulture = new RequestCulture("en-US"),
    SupportedCultures = supportedCultures,
    SupportedUICultures = supportedCultures
};

app.UseRequestLocalization(localizationOptions);

How Culture is Selected

ASP.NET Core determines culture from:

  1. Query string

  2. Cookies

  3. Request headers (Accept-Language)

Example Header

Accept-Language: fr-FR

Localization Using Resource Files (.resx)

Step 1: Create Resources Folder

Resources/
 └── Controllers.HomeController.en-US.resx
 └── Controllers.HomeController.fr-FR.resx

Step 2: Add Resource Keys

English (en-US)

KeyValue
WelcomeMessageWelcome to our store

French (fr-FR)

KeyValue
WelcomeMessageBienvenue dans notre magasin

Using Localized Text in Controller

using Microsoft.Extensions.Localization;

[ApiController]
[Route("api/home")]
public class HomeController : ControllerBase
{
    private readonly IStringLocalizer<HomeController> _localizer;

    public HomeController(IStringLocalizer<HomeController> localizer)
    {
        _localizer = localizer;
    }

    [HttpGet]
    public IActionResult Get()
    {
        return Ok(_localizer["WelcomeMessage"]);
    }
}

Request Example (Real-Time)

English Request

GET /api/home
Accept-Language: en-US

Response

"Welcome to our store"

French Request

GET /api/home
Accept-Language: fr-FR

Response

"Bienvenue dans notre magasin"

Globalization Example (Date & Currency)

[HttpGet("date")]
public IActionResult GetDate()
{
    return Ok(new
    {
        Date = DateTime.Now.ToString("D"),
        Price = (1234.50).ToString("C")
    });
}

Output by Culture

CultureDateCurrency
en-USJanuary 1, 2026$1,234.50
fr-FR1 janvier 20261 234,50 €
ar-SA١ يناير ٢٠٢٦ر.س 1,234.50

Using Query String for Culture

GET /api/home?culture=ar-SA

Interview-Ready Questions & Answers

Q1: What is globalization?

Globalization prepares an application to support multiple cultures and formats.

Q2: What is localization?

Localization adapts the application content to a specific language or region.

Q3: How does ASP.NET Core select culture?

Through query string, cookies, and request headers.

Q4: What are .resx files?

Resource files that store translated strings for different languages.

Summary

ConceptPurpose
GlobalizationCulture formatting
LocalizationLanguage translation
Resource filesStore translations
Request headersSelect language
ASP.NET CoreBuilt-in support