Mark
Mark

Reputation: 5038

ASP.NET Core 2.0: resource namespace not visible

I'm trying to make an ASP.NET Core 2.0 application multi-language. I created a resource file under a folder "Resources" called "Resource.it.resx". I set its access modifier to Public and its Namespace to Resources.

After (re)building the solution I cannot see this namespace in the C# code now in the cshtml code.

Is there some other steps to do?

Upvotes: 1

Views: 1157

Answers (2)

Camilo Terevinto
Camilo Terevinto

Reputation: 32068

There are two things you need to take into account:

  1. Only a Resource.resx generates a namespace, culture-specific resources such as Resource.it.resx does not generate a namespace. This is the intended behavior.
  2. ASP.NET Core's localization practices suggest not to use resources directly, but rather find the localized strings using IStringLocalizer.

I suggest you to read the fundamentals of ASP.NET Core localization in the official MSDN guide. There you will find examples for localizing strings in Controllers, Views and wherever you need them.

Upvotes: 1

lasha maraneli
lasha maraneli

Reputation: 87

First thing check if your resource namespace is visible in controller, like Resources.Resource.

I had not and in this situation I have created emtpy resource class, ex. my resources name is ServiceResources.en-US.resx, in same folder I have ServiceResources.cs empty class too.

Check if you have imported your namespace in _ViewImports.cshtml correctly, with IStringLocalizer class.

Upvotes: 1

Related Questions