Globalization (G11N): The process of making an app support different languages and regions.
Localization (L10N): The process of customizing a globalized app for specific languages and regions
To allow the app to support different languages by externalizing user-facing strings into resource files.
resx resource files to store localized strings.Project.Shared).AddViewLocalization(...) enables localized Razor Views (e.g., Index.ar.cshtml).AddDataAnnotationsLocalization() enables localization of [Display], [Required], and other attributes.var builder = WebApplication.CreateBuilder(args);
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddControllersWithViews()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
// example for using localization with data annotation
public class ProductDTO
{
public Guid? Id { get; set; }
[Required(ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = "ProductNameRequired")]
[StringLength(100, ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = "ProductNameMaxLength")]
public string Name { get; set; }
[StringLength(500, ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = "DescriptionMaxLength")]
public string Description { get; set; }
[Required(ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = "PriceRequired")]
[Range(0.01, 1000000, ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = "PriceRange")]
public double Price { get; set; }
}
AddLocalization: Registers the localization services. (IStringLocalizaer, IHtmlLocalizer, IViewLocalizer, IStringLocalizerFactory)ResourcesPath = "Resources": Looks for .resx files in the /Resources folder inside the Presentation layer.LanguageViewLocationExpanderFormat.Suffix?
Suffix option tells ASP.NET Core to look for culture-specific views by appending the culture name as a suffix to the view file name.