Hi all I'm involved in a localization project. We are working with areas and we need to create the resource file for the languages supported. The default structure ( Resources/Controllers/controllername.culture.resx) work correctly like Microsoft docs. we would like know the directory structure for the rest areas. We have looked for some docs but none we have found. Thx to all
Resource files for C# objects (not views) are being resolved by the namespace
they are in. They are relative to the ResourcePath
set during the initialization of MVC localization.
Let's say you have set the ResourcesPath
in your to "Resources"
services.AddLocalization(s => s.ResourcesPath = "Resources");
and you have a HomeController
like this:像这样的的HomeController
:
namespace WebApp.Controllers
{
public class HomeController : Controller
{
...
}
}
then your resource files in the folder Resources>Controllers>HomeController.{culture}.resx
will be picked up.
In case of a controller you might change to a different namespace like this:您可能会更改为不同的命名空间,如下所示:
namespace WebApp.Admin.Controllers
{
[Area("admin")]
public class HomeController : Controller
{
...
}
}
Note, this is the HomeController
of the admin area.
In this case your resource files for this particular controller can live in the folder:
Resources>Admin>Controllers>HomeController.{culture}.resx
can have this naming:可以有这样的命名:
Admin.Controllers.HomeController.{culture}.resx
This works in ASP.NET Core 1.1.0. I have updated the AspNetCore.Identity.Localization project with an area.
If you are using Areas, just put you controllername.culture.resx
in the Controllers
directory (exactly where controllername.cs
is, don't create a 'Resources' directory anywhere).
I suggest you to test with a simple resx ( controllername.resx
). If it works, you can extend it with controllername.culture.resx
Maybe this a bit late answer but however I want to participate, first of all setting the main path as Resource is not enough for configuration. If you have area you must follow these steps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.