toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.52k stars 259 forks source link

Issue with Encoding. Localization, especially Ru language #465

Open AndreyMisnikov opened 2 years ago

AndreyMisnikov commented 2 years ago

Hello!

If I define razor light engine as RazorLightEngine engine = new RazorLightEngineBuilder() .UseEmbeddedResourcesProject(typeof(RazorModel)) .SetOperatingAssembly(typeof(RazorModel).Assembly) .UseMemoryCachingProvider() .Build();

and then use engine.CompileRenderStringAsync(razorTemplateKey, content, model)

I have the issue with encoding when my content contains Russian. Is it possible to specify some kind of encoding for Engine by default?

I have created a lot of templates in my project with localization and as temporary fix I use content = "@using RazorLight @{ DisableEncoding = true; }" + content;

I would like to have an option to set some property to engine and be able to work with any language.

jzabroski commented 2 years ago

What you are describing as a temporary fix is the de facto approach:

https://github.com/toddams/RazorLight#encoding

If you want to contribute an alternative approach, I am open to shipping a PR.

jzabroski commented 2 years ago

@AndreyMisnikov any feedback/thoughts?