I have created a Resources
folder inside my ASP.NET Core solution and have created resx files for translations. I have resx files for models, pages and controllers. I would like to know where to put a resx file inside the Resource
s folder when there is a inputmodel inside a pagemodel?
This is an old question and maybe not relevant now, but I just had the same problem and was able to figure it out, so I'll add what worked for me.
It is really just a minor detail. If we want the resource for the page model, we would have Resources\Pages\IndexModel.en.resx
, for a class that's internal to that page model, we add a +InnerModel
, ending up with Resources\Pages\IndexModel+InnerModel.en.resx
I created a GitHub repository with a working sample here -> https://github.com/joaofbantunes/AspNetCoreRazorPagesInnerModelLocalizationSample
lets assume that we have a razor page under pages folder as below:
Pages/MyPage.cshtml
and its model page:
Pages/MyPage.cshtml.cs
your resource folder is located in the Project root beside Pages folder as below:
Project Root
-- Pages
-- Resources
MyPages input model by default is:
MyPageModel
Naming of the resource files deffers according to view localization setup in your startup.cs file,
Dotted naming :
if you used per view resource files with "suffix" option:
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
then you have to follow dotted naming for the resource files:
Resources/Pages.MyPage.en-US.resx // localization resource for view
Resources/Pages.MyPageModel.en-US.resx // localization resource for input model
Subfolder naming
if you used per view resource files with "Subfolder" option:
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddViewLocalization(LanguageViewLocationExpanderFormat.SubFolder);
then you have to create folder structure for resource files similar to the view folder strcuture:
Resources/Pages/MyPage.en-US.resx // localization resource for view
Resources/Pages/MyPageModel.en-US.resx // localization resource for input model
There is another option, which is using shared resource files, instead of creating one resource per view per language you may create only one resource file for all views per language, if you are intereseted in using shared resources you may visited this blog page: http://www.ziyad.info/en/articles/10-Developing_Multicultural_Web_Application
© 2022 - 2024 — McMap. All rights reserved.