I’m trying to use the localization feature of ASP.Net Core in my Blazor app. I want to use IStringLocalizer so that I automatically detect the browser language to adapt to the user’s language. My solution consists of several projects and for cleanliness I wanted to gather the resource files in one and the same project (app.core) for all my other projects. you can see an example of my architecture :
solution app
|-- app.project1
|-- app.project2
|-- app.core
| |-- Resources
| |-- Localization
| |-- project1
| |-- project2
| |-- web
| |-- Pages
| |-- Index.en.resx
| |-- Index.fr.resx
|-- app.web
|-- Pages
|-- Index.razor
Resources related to the web project are located in the core project in the folder Resources > Localization > web.
I have looked at several existing questions before to orient myself, but I have not found a solution to my problem (or maybe I'm bad lol) :
- Asp.Net Core Localized Resource in Separate Assembly
- .NET Core - Globalization and Localization - Class library
- Localization in external class libraries in ASP.NET Core
- Support localization resources in a separate assembly
When I put my resources in the same project, it works so it’s just that I can’t figure out how to do it when it’s in another project.
What I tried: In my web project in Configureservice
I have .AddLocalization()
and .Configure<RequestLocalizationOptions>(opt => ...)
and in Configure
I have app.UseRequestLocalization()
. In my core project I created an AssemblyInfo.cs
with [assembly: ResourceLocation("Resources/Localization/web")]
and [assembly: RootNamespace("app")]
(and other names like app.web
, or app.core
) but it doesn’t seem to work.
I don't like the solution to do dummy .cs for each .resx, I don't like to have useless classes.
I hope my problem is understandable and my English too. Thank you in advance for your answers, this is the first time I’ve come to ask for help here!