Razor.Templating.Core icon indicating copy to clipboard operation
Razor.Templating.Core copied to clipboard

Support MVC view localization

Open superware opened this issue 1 year ago • 2 comments

Hello,

After configuring:

services.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
services.AddRazorTemplating();
...
app.UseRequestLocalization("fr");

MVC will locate and use the view Views/Home/Index.fr.cshtml since the locating mechanism is searching for the correct view file using the Controller and View names, but _razorTemplateEngine.RenderAsync("/Views/Home/Index.cshtml") obviously doesn't support localization.

So one way is to explicitly render /Views/EmailTemplates/ConfirmEmail.fr.cshtml which is totally lame, but a better way will be to do all that automatically. So a French user registering the web app will receive the French confirmation email.

It will be awesome if localization support can be added, my guess by internally detecting AddViewLocalization and LanguageViewLocationExpanderFormat.Suffix, and when rendering maybe use LanguageViewLocationExpander to yield all possible localized views and FindView until found. I guess /Views/Home/Index.cshtml can be internally transformed to /Views/Home/{0}.cshtml for this case (ExpandViewLocations).

Any thoughts?

superware avatar Apr 07 '24 20:04 superware