Last post Mar 17, 2017 04:56 PM by bebleu
Mar 15, 2017 02:38 PM|bebleu|LINK
I'm trying to add localization on .Net Core 1.1 using Visual Studio 2017.
Every time I try to localize from an injected HtmlLocalizer in my view, it returns the global resource value (SharedResources.resx).
I tried with the IViewLocalizer with resx files with the same name as the view without success.
I created a folder Resources, added SharedResources.cs, SharedResources.en.resx, SharedResources.fr.resx and SharedResources.resx in it.
Here is my code :
public void ConfigureServices(IServiceCollection services)
services.AddLocalization(options => options.ResourcesPath = "Resources");
// Add framework services.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
var supportedCultures = new 
DefaultRequestCulture = new RequestCulture("fr"),
// Formatting numbers, dates, etc.
SupportedCultures = supportedCultures,
// UI strings that we have localized.
SupportedUICultures = supportedCultures
@inject IViewLocalizer Localizer
@inject IHtmlLocalizer<SharedResources> SharedHtmlLocalizer
ViewData["Title"] = "About";
<p>Use this area to provide additional information.</p>
public class SharedResources
Resources folder :
Is there something I'm doing wrong ? I can't see what's the problem here..
Thanks a lot
Mar 16, 2017 09:42 AM|damienBod|LINK
looks all right, try setting the culture to one of your configured cultures
and see if it works, the browser might be sending a non-supported culture.
Mar 16, 2017 01:53 PM|bebleu|LINK
Tried http://localhost:53834/Home/About?culture=en-US&ui-culture=en-US and http://localhost:53834?culture=en-US&ui-culture=en-US but
the problem still persists.
I also did run my project from Chrome, Internet Explorer and Edge with the same results.
Still got no idea why the resource is always taken from the default resx file.
Mar 16, 2017 02:55 PM|Radomir|LINK
Have you seen this part from
"Generating resource files with Visual Studio
If you create a resource file in Visual Studio without a culture in the file name (for example,
Welcome.resx), Visual Studio will create a C# class with a property for each string. That's usually not what you want with ASP.NET Core; you typically don't have a default
.resx resource file (A .resx file without the culture name). We suggest you create the
.resx file with a culture name (for example Welcome.fr.resx). When you create a
.resx file with a culture name, Visual Studio will not generate the class file. We anticipate that many developers will
not create a default language resource file."
Mar 16, 2017 04:03 PM|Radomir|LINK
Btw, removing (options => options.ResourcesPath
= "Resources") from services.AddLocalization is what makes it work for me...
Mar 16, 2017 07:49 PM|bebleu|LINK
Thanks for the tips.
I removed SharedResources.resx and kept only those with the locale. Now all I got is the key of the resource.
I also tried by removing the options in services.AddLocalization, but it changed nothing on my side.
Mar 16, 2017 08:03 PM|Radomir|LINK
If you're getting the key then it's not finding (or should I say "matching") those resources... .just printing out the key is default behavior.
You can debug this by adding some code from that article mentioned (ie into the controller -- stuff with resource factory - that code) and see what you see for "localizer" -- is it picking up the right resources etc.. is the "namespace" correct (that's
the reason I had to remove that options thing.. it was adding extra Resources into the "namespace" for the localizer hence not finding the proper resource set..
Mar 17, 2017 04:56 PM|bebleu|LINK
Thanks a lot, you were really helpful.
Il downloaded a sample code from https://github.com/aspnet/Entropy and saw Nuget Packages that wasn't in my projet.
"Localization.AspNetCore.TagHelpers" and "Microsoft.AspNetCore.Authentication.Cookies"
Installing them resolved my issue.
Thanks a lot !