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
Helping you always. Don't forget to click "Mark as Answer" on the post that helped you.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
Member
16 Points
131 Posts
Language Translation is always English
Jul 03, 2020 12:52 PM|roguenidb|LINK
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.
Configure section
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.
Participant
1861 Points
2836 Posts
Re: Language Translation is always English
Jul 03, 2020 11:22 PM|EnenDaveyBoy|LINK
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)
Participant
1253 Points
935 Posts
Re: Language Translation is always English
Jul 04, 2020 05:17 AM|yogyogi|LINK
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
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠