I need to have some strings given from resource file in my views. In Startup.cs:
services.AddMvc()
.AddViewLocalization(options => options.ResourcesPath = "Resources");
and:
app.UseRequestLocalization(new RequestCulture("ru-RU"));
View:
@using Microsoft.AspNet.Mvc.Localization
@inject IViewLocalizer loc
I read in the MSDN blog the following:
The
IViewLocalizer
is anIHtmlLocalizer
service that looks for a resource based on the current view name.
So how should I name .resx
files so that my localized strings appear in my view? If I've got Views/Manager/Index.cshtml
then Resources/Manager/Index.cshtml.ru-RU.resx
is correct? But the resource isn't been found...
this is pretty confusing in the documentation, because the resource name is not based on the current view name, but on the current view path:
https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Localization/ViewLocalizer.cs
(line 101)
This means resource name should be named like this:
Views.{ControllerName}.{ViewName}.cshtml.{culture code}.resx
e.g. Views.Home.About.cshtml.de-DE.resx
I already reported this behavior a month ago:
https://github.com/aspnet/Mvc/issues/3376
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With