Trying to localize my application, I did the following: https://docs.asp.net/en/latest/fundamentals/localization.html
Here is my code:
Startup.cs
public List<IRequestCultureProvider> RequestCultureProviders { get; private set; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddLocalization(options => options.ResourcesPath = "Resources"); services.AddMvc() .AddViewLocalization(options => options.ResourcesPath = "Resources") .AddDataAnnotationsLocalization(); services.AddOptions(); services.AddTransient<IViewRenderingService, ViewRenderingService>(); services.AddTransient<IEmailSender, EmailSender>(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { var locOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>(); app.UseRequestLocalization(locOptions.Value); app.UseStaticFiles(); app.UseFileServer(new FileServerOptions() { FileProvider = new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory())), EnableDirectoryBrowsing = true }); var supportedCultures = new[] { new CultureInfo("en-US"), new CultureInfo("fr"), }; app.UseRequestLocalization(new RequestLocalizationOptions { DefaultRequestCulture = new RequestCulture("fr"),
Mycontroller.cs
public class MyController : Controller { private readonly IViewRenderingService _viewRenderingService; private IStringLocalizer<MyController> _localizer; private MyOptions _options;
The *.resx is stored in the Resources folder under the name Controllers.MyController.fr.resx (it has an entry for "Product" in it).
However, it cannot find the resource file, and the Product is never returned in French. I use the query string, so here is the query string:
localhost:3333/my?culture=fr
Also in the view, @Localizer["Product"] returns "Product".
Can someone please help me find what is missing?
EDIT:
After some research, I found that the culture is changing, but it cannot find the resource file. I am using VS2015. can anyone help?
source share