11

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 Resources folder when there is a inputmodel inside a pagemodel?

2 Answers 2

14

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

1
  • the + notation is beyond stupid but it worked. Thanks May 18, 2021 at 14:15
-1

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

5
  • 1
    Thanks, for the descriptive answer, but it's not answering the question.
    – Givi
    Dec 14, 2018 at 15:09
  • okay, I think I misunderstood the question, as far as I understand now, you don't want to use shared resource files, right?
    – LazZiya
    Dec 19, 2018 at 8:37
  • Yup, I was wondering, is there any possibilities to use DataAnnotation localizations for inner classes. Like PageModel > InputModel
    – Givi
    Dec 19, 2018 at 9:44
  • Paths for resx-files is the same for Dotted naming and SubFolder naming, is this correct? I would expect the paths for Subfolder naming to be Resources/Pages/en-US/MyPage.resx May 6, 2019 at 15:43
  • @GuidoNeele yes the only difference is that you use dot ( . ) or slash ( / ), the rest is the same. for more details see resource naming in the docs
    – LazZiya
    May 7, 2019 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.