Quantcast
Viewing all articles
Browse latest Browse all 9386

ASP.NET Core (.NET Framework) and Localization

Why the libraries that I'm using in my ASP.NET Core project (.NET Framework) do not return messages translated as the selected culture?

For example:

ResourceManager rm = new ResourceManager(typeof(ClassLibrary1.Test));
string test1 = rm.GetString("Hello", new System.Globalization.CultureInfo("en-US"));
string test2 = rm.GetString("Hello", new System.Globalization.CultureInfo("pt-BR"));


This code is in a library part that has business rules and returns a message.

But when it is referenced in an ASP.NET MVC project it returns the message as the current culture (pt-br, en-us).

But if this library is referenced in a ASP.NET Core project (.NET Framework), nothing makes it return in the current culture.

ASP.NET

ResourceManager rm = new ResourceManager(typeof (ClassLibrary1.Test));
string test1 = rm.GetString("Hello", new System.Globalization.CultureInfo("en-US"));
string test2 = rm.GetString("Hello", new System.Globalization.CultureInfo("pt-BR"));

test1 = Message en-US
test2 = Message pt-BR


ASP.NET Core

ResourceManager rm = new ResourceManager(typeof(ClassLibrary1.Test));
string test1 = rm.GetString("Hello", new System.Globalization.CultureInfo("en-US"));
string test2 = rm.GetString("Hello", new System.Globalization.CultureInfo("pt-BR"));

test1 = Message pt-BR
test2 = Message pt-BR


Detail that everything is configured correctly on ASP.NET Core because:

IStringLocalizer <HomeController>
@Inject IViewLocalizer localizer

It works perfectly.

The problem is in the Resources of the referenced libraries.

Can someone help me?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>