ASP.NET core razor pages localization for inputmodel inside pagemodel
Asked Answered
P

2

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?

Photoelasticity answered 8/7, 2018 at 20:34 Comment(0)
I
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

Infiltrate answered 9/2, 2019 at 11:7 Comment(1)
the + notation is beyond stupid but it worked. ThanksDihydric
G
-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

Germanium answered 16/9, 2018 at 13:49 Comment(5)
Thanks, for the descriptive answer, but it's not answering the question.Raymer
okay, I think I misunderstood the question, as far as I understand now, you don't want to use shared resource files, right?Germanium
Yup, I was wondering, is there any possibilities to use DataAnnotation localizations for inner classes. Like PageModel > InputModelRaymer
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.resxJephum
@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 docsGermanium

© 2022 - 2024 — McMap. All rights reserved.