Answered by:
Language Translation is always English

Question
-
User-183185495 posted
I have a strange problem my translations are always coming back in English. I have made sure that edge has the languages installed but still its always English. BTW as a test I only have the words of different countries in the text to ensure they get rendered.
public void ConfigureServices(IServiceCollection services) { services.AddLocalization(options => options.ResourcesPath = "Resources"); services.AddSingleton<LocalizationService>(); services.AddDbContext<MISDBContext> (options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity<ApplicationUser>() AddEntityFrameworkStores<MISDBContext() .AddClaimsPrincipalFactory<MyUserClaimsPrincipalFactory>(); //<---- add this line services.AddControllersWithViews() .AddDataAnnotationsLocalization(); services.Configure<RequestLocalizationOptions>(options => { var supportedCultures = new[] { new CultureInfo("en-US"), new CultureInfo("en-GB"), new CultureInfo("es"), new CultureInfo("fr") }; options.DefaultRequestCulture = new RequestCulture(culture: "en-GB", uiCulture: "en-GB"); options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; options.RequestCultureProviders = new List<IRequestCultureProvider> { new QueryStringRequestCultureProvider(), new CookieRequestCultureProvider() }; }).AddRazorPages(). AddViewLocalization() .AddDataAnnotationsLocalization(options => { options.DataAnnotationLocalizerProvider = (type, factory) => { var assemblyName = new AssemblyName(typeof(SharedResource).GetTypeInfo().Assembly.FullName); return factory.Create("SharedResource", assemblyName.Name); }; }); services.AddSingleton<ISharedResource, SharedResource>(); }
Configure section
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRequestLocalization(); var supportedCultures = new[] { new CultureInfo("en-US"), new CultureInfo("en-GB"), new CultureInfo("es"), new CultureInfo("fr") }; if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/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.UseRequestLocalization(new RequestLocalizationOptions() { DefaultRequestCulture = new RequestCulture("en-GB"), SupportedCultures = supportedCultures, SupportedUICultures = supportedCultures }); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); });
}Showing Different resource files
This is the spanish transations which it should be picking up
Showing Debugging
Shwoing culture info debug
Just to prove that the cookie is being update.
Friday, July 3, 2020 12:52 PM
Answers
-
User-2054057000 posted
It seems resource files are not getting called on when you change your culture. Refer Globalization and Localization with Resource Files in ASP.NET Core
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, July 4, 2020 5:17 AM
All replies
-
User1034446946 posted
can you confirm you have converted the text into the required language?
your spanish transaltion seems to be in english.
(it doesn't translate it for you)
Friday, July 3, 2020 11:22 PM -
User-2054057000 posted
It seems resource files are not getting called on when you change your culture. Refer Globalization and Localization with Resource Files in ASP.NET Core
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, July 4, 2020 5:17 AM