RESX resource files are the default file type for localization. But, RESX files do not support editing at runtime! So if you do not want to fill them manually, start localization setup based on XML or DB, then export the resources to RESX files.
Then we can create our localized resources files under LocalizationResources folder as below:
LocSource.tr.resx
LocSource.ar.resx
...
Full startup code for RESX:
usingMicrosoft.AspNetCore.Builder;usingMicrosoft.AspNetCore.Hosting;usingMicrosoft.Extensions.Configuration;usingMicrosoft.Extensions.DependencyInjection;usingMicrosoft.Extensions.Hosting;usingSystem.Globalization;usingXLocalizer;usingXLocalizer.Routing;usingSampleProject.LocalizationResources;namespaceSampleProject{publicclassStartup{publicStartup(IConfigurationconfiguration){Configuration=configuration;}publicIConfigurationConfiguration{get;}// This method gets called by the runtime. Use this method to add services to the container.publicvoidConfigureServices(IServiceCollectionservices){services.Configure<RequestLocalizationOptions>(ops =>{varcultures=newCultureInfo[]{newCultureInfo("en"),newCultureInfo("tr"),newCultureInfo("ar")};ops.SupportedCultures=cultures;ops.SupportedUICultures=cultures;ops.DefaultRequestCulture=newMicrosoft.AspNetCore.Localization.RequestCulture("en");// Optional: add custom provider to support localization based on route value {culture}ops.RequestCultureProviders.Insert(0,newRouteSegmentRequestCultureProvider(cultures));});services.AddRazorPages()// Optional: Add {culture} route template to all razor pages routes e.g. /en/Index.AddRazorPagesOptions(ops =>{ops.Conventions.Insert(0,newRouteTemplateModelConventionRazorPages());})// Add XLocalizer with a default resource <LocSource>.AddXLocalizer<LocSource>(ops =>{ops.ResourcesPath="LocalizationResources";});}// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.publicvoidConfigure(IApplicationBuilderapp,IWebHostEnvironmentenv){if(env.IsDevelopment()){app.UseDeveloperExceptionPage();app.UseDatabaseErrorPage();}else{app.UseExceptionHandler("/Error");// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.app.UseHsts();}app.UseHttpsRedirection();app.UseStaticFiles();app.UseRouting();// Use request localization middlewareapp.UseRequestLocalization();app.UseEndpoints(endpoints =>{endpoints.MapRazorPages();});}}}