liveBook · Manning

Globalization

As explained in .NET in Action, Second Edition

Globalization is the preparation of software and its data for operation across different regions, cultures, languages, formats, and conventions.

Globalization prepares software and its data to adapt to users’ regions and cultures. It covers user-facing strings, dates, numbers, measurements, sort order, time zones, and language-dependent formats without requiring code changes for each added culture. section 12.0 section 12.5.1

Apply globalization by:

  • Setting the current culture and UI culture explicitly when testing regional behavior. section 12.5.1
  • Sending the selected culture to services through the HTTP Accept-Language header; thread culture alone does not add it automatically. section 12.5.1
  • Replacing concatenated user-facing sentences with resource labels containing substitution placeholders, allowing translation to reorder values. section 12.5.1
  • Testing input, output, and persisted data with dummy cultures to expose assumptions about string length, images, sorting, and date formats. section 12.5.2
Listing 12.14 Code for AcController.Client
using System.Globalization;
using System.Net.Http.Headers;
using System.Text.Json;
  
var culture = CultureInfo
  .CreateSpecificCulture("es-MX");                      #1
Thread.CurrentThread.CurrentCulture = culture;          #2
Thread.CurrentThread.CurrentUICulture = culture;
  
var client = new HttpClient() {
  BaseAddress = new Uri("http://localhost:<port>")      #3
};
client.DefaultRequestHeaders.AcceptLanguage.Add(        #4
  new StringWithQualityHeaderValue(culture.Name));      #5
  
var responseBody = await client.GetStringAsync(         #6
  "/measure/TIJ1/1");
var temps = JsonSerializer.Deserialize<TempsDto>(       #7
  responseBody, new JsonSerializerOptions() {
    PropertyNameCaseInsensitive = true
  }
);
  
Console.WriteLine("Timestamp: " +
  temps!.Timestamp.LocalDateTime);                      #8
Console.WriteLine("Site     : " + temps.Site);
Console.WriteLine("Unit ID  : " + temps.UnitId);
foreach (var measure in temps.Measurements)
{
  Console.WriteLine(
    measure.Description.PadLeft(36)                     #9
    + ": " + measure.Value + " C");                     #10
}
  
internal record TempsDto(                               #11
  int UnitId,
  string Site,
  DateTimeOffset Timestamp,
  IEnumerable<MeasurementDto> Measurements
) { }
  
public record MeasurementDto(
  string SensorName,
  decimal Value,
  string Description
) { }

A C# client demonstrates selecting an es-MX culture, applying it to the current thread, forwarding it with Accept-Language, calling an API, and displaying sensor data. section 12.5.1

Avoiding language-order assumptions

A reading such as “Outside Air Temperature: 20 C” assumes a fixed sentence order. Resource placeholders let translations reposition the value, while right-to-left handling can reverse the label and value when required. section 12.5.1

How .NET in Action, Second Edition covers it

How deep it goes
Descends from terminology into culture selection, HTTP propagation, resource placeholders, right-to-left output, and testing, but not complete localization.
Examples
Uses an es-MX sensor client, resource placeholders, right-to-left labels, Fahrenheit-by-region exercise, and dummy cultures.
What it assumes
Assumes intermediate C# and introduces globalization terminology, culture selection, resource placeholders, and review techniques.
What you can do after
Build it from scratch by creating culture-aware clients and outputs that avoid fixed language, formatting, and ordering assumptions.
How it connects
Connects internationalization, localization, localizability review, culture, resource files, HTTP headers, and satellite assemblies.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.